Vite: The CJS build of Vite's Node API is deprecated
Environment
vite: 5.4.21
@sentry/vite-plugin: 4.9.1
Steps to Reproduce
- Run
viteorvite build
Expected Result
Vite should complete the build without activating CJS mode. The issue was introduced in d3236bdbc1a7bea26c7f375ffd47c8d5f2213fa7
Actual Result
The CJS build of Vite's Node API is deprecated. See https://vite.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details. at warnCjsUsage (/Users/<USER>/<WORK>/<PROJECT>/node_modules/vite/index.cjs:50:11) at Object.<anonymous> (/Users/<USER>/<WORK>/<PROJECT>/node_modules/vite/index.cjs:1:1) at getViteMajorVersion (file:///Users/<USER>/<WORK>/<PROJECT>/node_modules/@sentry/vite-plugin/dist/esm/index.mjs:40:16) at file:///Users/<USER>/<WORK>/<PROJECT>/node_modules/@sentry/bundler-plugin-core/dist/esm/index.mjs:9879:110 at Object.<anonymous> (file:///Users/<USER>/<WORK>/<PROJECT>/node_modules/unplugin/dist/index.mjs:1201:32) at sentryVitePlugin (file:///Users/<USER>/<WORK>/<PROJECT>/node_modules/@sentry/vite-plugin/dist/esm/index.mjs:55:31) at file:///Users/<USER>/<WORK>/<PROJECT>/vite.config.ts.timestamp-XXXXXXXXXXXX.mjs:13:5 at async loadConfigFromBundledFile (file:///Users/<USER>/<WORK>/<PROJECT>/node_modules/vite/dist/node/chunks/dep-XXXX.js:66975:15) at async loadConfigFromFile (file:///Users/<USER>/<WORK>/<PROJECT>/node_modules/vite/dist/node/chunks/dep-XXXX.js:66816:24) at async resolveConfig (file:///Users/<USER>/<WORK>/<PROJECT>/node_modules/vite/dist/node/chunks/dep-XXXX.js:66416:24) at async _createServer (file:///Users/<USER>/<WORK>/<PROJECT>/node_modules/vite/dist/node/chunks/dep-XXXX.js:63015:18) at async CAC.<anonymous> (file:///Users/<USER>/<WORK>/<PROJECT>/node_modules/vite/dist/node/cli.js:736:20)
Hey @AleG94, thanks for reporting! @timfish could you take a look at this please, thanks!
Looks like this is caused by the fact that we use createRequire to lazily fetch the Vite version because we needed to keep it synchronous!
This warning doesn't exist in any of the recent Vite majors.
We can get the Vite version via async import but then the async will propagate through and make the plugin initialization async and I don't think this is worth doing to suppress a warning in v5.