Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation fails after upgrading to Vite 5 #21

Closed
Vilican opened this issue Nov 29, 2023 · 10 comments
Closed

Compilation fails after upgrading to Vite 5 #21

Vilican opened this issue Nov 29, 2023 · 10 comments
Labels
question Further information is requested

Comments

@Vilican
Copy link

Vilican commented Nov 29, 2023

Full error message:

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.
failed to load config from C:\Users\<user>\PhpstormProjects\<project>\vite.config.ts
error when starting dev server:
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\<user>\PhpstormProjects\<project>\node_modules\@poppinss\cliui\build\index.js from C:\Users\<user>\PhpstormProjects\<project>\node_modules\@julr\vite-plugin-validate-env\dist\index.cjs not supported.
Instead change the require of index.js in C:\Users\<user>\PhpstormProjects\<project>\node_modules\@julr\vite-plugin-validate-env\dist\index.cjs to a dynamic import() which is available in all CommonJS modules.
    at _require.extensions.<computed> [as .js] (file:///C:/Users/<user>/PhpstormProjects/<project>/node_modules/vite/dist/node/chunks/dep-4RECYSE1.js:67481:17)
    at Object.<anonymous> (C:\Users\<user>\PhpstormProjects\<project>\node_modules\@julr\vite-plugin-validate-env\dist\index.cjs:7:15)
    at _require.extensions.<computed> [as .js] (file:///C:/Users/<user>/PhpstormProjects/<project>/node_modules/vite/dist/node/chunks/dep-4RECYSE1.js:67481:17)

Process finished with exit code 1
@Julien-R44
Copy link
Owner

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".

@Julien-R44 Julien-R44 added the question Further information is requested label Nov 29, 2023
@Vilican
Copy link
Author

Vilican commented Nov 29, 2023

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)

@paolostyle
Copy link

paolostyle commented Dec 5, 2023

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)

@gunta
Copy link

gunta commented Dec 7, 2023

Reproducing here too.

@gunta
Copy link

gunta commented Dec 7, 2023

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

@Julien-R44
Copy link
Owner

Thanks guys. So that means it's probably coming from unconfig. I'll investigate before the end of the week

@ujwal-setlur
Copy link

Hi @Julien-R44, any update on this? I am getting this warning as well

@wowblvck
Copy link

Hi @Julien-R44. I have a same warning too. Is there any solution?

@Julien-R44
Copy link
Owner

haven't had time to investigate yet. happy to review a PR for this

@Julien-R44
Copy link
Owner

Fixed with version 1.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants