Vite 3 issue
Describe the bug
When using vite 3, an error occurs when starting the server:
error when starting dev server:
TypeError: (0 , import_tiny_invariant.default) is not a function
at TscChecker.initMainThread (/Users/kev-laptop/dev/vite-project/node_modules/vite-plugin-checker/dist/cjs/Checker.js:57:39)
at TscChecker.init (/Users/kev-laptop/dev/vite-project/node_modules/vite-plugin-checker/dist/cjs/checkers/typescript/main.js:152:40)
at Object.<anonymous> (/Users/kev-laptop/dev/vite-project/node_modules/vite-plugin-checker/dist/cjs/checkers/typescript/main.js:159:12)
at Module._compile (node:internal/modules/cjs/loader:1155:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
at Module.load (node:internal/modules/cjs/loader:1033:32)
at Function.Module._load (node:internal/modules/cjs/loader:868:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Reproduction
My vite config looks like:
export const config = {
plugins: [
nodeResolve({
extensions: ['.ts', '.tsx', '.js', '.jsx'],
}),
reactPlugin({ injectReact: true }),
checker({ typescript: { tsconfigPath: './vite-tsconfig.json' } }),
visualizer({
filename: 'bundle-analysis.html',
}),
],
envPrefix: 'QS',
resolve: {
alias: [
// this is used for react-tooltip that generate uuid (needs crypto)
{
find: 'crypto',
replacement: 'crypto-browserify',
},
// this is used for the decryptor
{
find: 'stream',
replacement: 'readable-stream',
},
],
},
}
export default defineConfig(() => config)
Expected behavior
I expect this error to not happen.
System Info
System:
OS: macOS 11.5.2
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 181.48 MB / 16.00 GB
Shell: 3.3.1 - /usr/local/bin/fish
Binaries:
Node: 16.18.0 - ~/.volta/tools/image/node/16.18.0/bin/node
Yarn: 1.22.19 - ~/.volta/tools/image/yarn/1.22.19/bin/yarn
npm: 8.19.2 - ~/.volta/tools/image/npm/8.19.2/bin/npm
Browsers:
Chrome: 107.0.5304.87
Firefox Developer Edition: 104.0
Safari: 14.1.2
npmPackages:
vite-plugin-checker: ^0.5.1 => 0.5.1
Additional context
No response
Validations
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Could you provide a minimal reproduction? I created a demo project with Vite3's offical scaffold and changed type: "commonjs" in package.json but still can not re-produce it.
A repro, even if it's using Vite 2 and is related to stylelint
https://github.com/IlCallo/vite-plugin-checker-stylelint-error-cjs
It's a monorepo with Quasar and NestJS, it's managed via PNPM (with hoisting enabled)
Running pnpm run client:dev it will break
If you comment these lines and rerun it, it will succeed and open the Quasar project
The same problem happens when forcing the usage of Vite 4 using these workarounds
this is still broken for me with "vite": "^4.0.4" and "vite-plugin-checker": "^0.5.5"
+1 I'm also seeing this issue. Probably unrelated but tiny-invariant NPM page (here) seem to suggest that it has a dependancy on process.env.NODE_ENV being available at compile which would be an issue since Vite doesn't provide that.
The error message
error when starting dev server:
TypeError: (0 , import_tiny_invariant.default) is not a function
at TscChecker.initMainThread (xxx/node_modules/vite-plugin-checker/dist/cjs/Checker.js:57:39)
at TscChecker.init (xxx/node_modules/vite-plugin-checker/dist/cjs/checkers/typescript/main.js:156:40)
at Object.<anonymous> (xxx/node_modules/vite-plugin-checker/dist/cjs/checkers/typescript/main.js:163:12)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Versions
I've also tried with [email protected] and the same error occurs.
Vite config
/// <reference types="vitest" />
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
import checker from "vite-plugin-checker";
import svgrPlugin from "vite-plugin-svgr";
import viteTsconfigPaths from "vite-tsconfig-paths";
export default defineConfig({
plugins: [
react(),
viteTsconfigPaths(),
svgrPlugin(),
checker({
typescript: true,
}),
],
server: {
port: 3000,
},
build: {
outDir: "build",
},
});
Update on this: I've found that installing tiny-invariant myself fixes the issue 🎉
npm install -D tiny-invariant
We were running into the same issue.
yarn add -D tiny-invariant
Didn't help initially, I then realized yarn.lock had both 1.1.0 and 1.3.1 references, so once I got rid of 1.1.0, this issue was resolved for me too. Nice find!