Closed Vilican closed 6 months ago
Is your project in ESM? Please read the link Vite gives you just before the error message: https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated
Your package.json should have "type": "module".
Yeah, thanks for the quick fix. It still gives a warning though:
Trace: The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
at warnCjsUsage (C:\Users\<user>\PhpstormProjects\<project>\node_modules\vite\index.cjs:32:3)
at Object.<anonymous> (C:\Users\<user>\PhpstormProjects\<project>\node_modules\vite\index.cjs:3:1)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18)
at Object.<anonymous> (C:\Users\<user>\PhpstormProjects\<project>\node_modules\@julr\vite-plugin-validate-env\dist\index.cjs:6:14)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18)
at evalModule (C:\Users\<user>\PhpstormProjects\<project>\node_modules\jiti\dist\jiti.js:1:255612)
at jiti (C:\Users\<user>\PhpstormProjects\<project>\node_modules\jiti\dist\jiti.js:1:254371)
at C:/Users/<user>/PhpstormProjects/<project>/env.ts:3:30
at evalModule (C:\Users\<user>\PhpstormProjects\<project>\node_modules\jiti\dist\jiti.js:1:256443)
at jiti (C:\Users\<user>\PhpstormProjects\<project>\node_modules\jiti\dist\jiti.js:1:254371)
at loadConfigFile (file:///C:/Users/<user>/PhpstormProjects/<project>/node_modules/unconfig/dist/index.mjs:153:13)
at async Object.load (file:///C:/Users/<user>/PhpstormProjects/<project>/node_modules/unconfig/dist/index.mjs:76:24)
at async loadConfig (file:///C:/Users/<user>/PhpstormProjects/<project>/node_modules/@julr/vite-plugin-validate-env/dist/index.mjs:81:18)
at async validateEnv (file:///C:/Users/<user>/PhpstormProjects/<project>/node_modules/@julr/vite-plugin-validate-env/dist/index.mjs:115:15)
at async runConfigHook (file:///C:/Users/<user>/PhpstormProjects/<project>/node_modules/vite/dist/node/chunks/dep-4RECYSE1.js:67497:25)
at async resolveConfig (file:///C:/Users/<user>/PhpstormProjects/<project>/node_modules/vite/dist/node/chunks/dep-4RECYSE1.js:66950:14)
at async _createServer (file:///C:/Users/<user>/PhpstormProjects/<project>/node_modules/vite/dist/node/chunks/dep-4RECYSE1.js:59489:20)
at async CAC.<anonymous> (file:///C:/Users/<user>/PhpstormProjects/<project>/node_modules/vite/dist/node/cli.js:764:24)
I have the same issue, I did not have the warning before using this plugin, seems like it's something in that jiti
dependency, though it's a bit ironic considering what that package does 🤷 Adding the stack trace as well:
$ VITE_CJS_TRACE=true npx vite build
Trace: The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
at warnCjsUsage (/home/<project>/node_modules/vite/index.cjs:32:3)
at Object.<anonymous> (/home/<project>/node_modules/vite/index.cjs:3:1)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at require (node:internal/modules/cjs/helpers:119:18)
at Object.<anonymous> (/home/<project>/node_modules/@julr/vite-plugin-validate-env/dist/index.cjs:6:14)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at require (node:internal/modules/cjs/helpers:119:18)
at evalModule (/home/<project>/node_modules/unconfig/node_modules/jiti/dist/jiti.js:1:255612)
at jiti (/home/<project>/node_modules/unconfig/node_modules/jiti/dist/jiti.js:1:254371)
at /home/<project>/env.mts:1:192
at evalModule (/home/<project>/node_modules/unconfig/node_modules/jiti/dist/jiti.js:1:256443)
at jiti (/home/<project>/node_modules/unconfig/node_modules/jiti/dist/jiti.js:1:254371)
at loadConfigFile (file:///home/<project>/node_modules/unconfig/dist/index.mjs:153:13)
at async Object.load (file:///home/<project>/node_modules/unconfig/dist/index.mjs:76:24)
at async loadConfig (file:///home/<project>/node_modules/@julr/vite-plugin-validate-env/dist/index.mjs:81:18)
at async validateEnv (file:///home/<project>/node_modules/@julr/vite-plugin-validate-env/dist/index.mjs:115:15)
at async runConfigHook (file:///home/<project>/node_modules/vite/dist/node/chunks/dep-4RECYSE1.js:67497:25)
at async resolveConfig (file:///home/<project>/node_modules/vite/dist/node/chunks/dep-4RECYSE1.js:66950:14)
at async build (file:///home/<project>/node_modules/vite/dist/node/chunks/dep-4RECYSE1.js:66093:20)
at async CAC.<anonymous> (file:///home/<project>/node_modules/vite/dist/node/cli.js:845:9)
Reproducing here too.
Can confirm it breaks when trying to load from a separate file (env.ts), but it works fine when is in the vite.config.mts file
Thanks guys. So that means it's probably coming from unconfig
. I'll investigate before the end of the week
Hi @Julien-R44, any update on this? I am getting this warning as well
Hi @Julien-R44. I have a same warning too. Is there any solution?
haven't had time to investigate yet. happy to review a PR for this
Fixed with version 1.1.1
Full error message: