iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
⚡️
React Router v7 + Node v20: Resolving 'The CJS build of Vite's Node API is deprecated' Warning
When I created a React Router v7 project from the template (npx create-react-router@latest) and started it (npm run dev), I received a warning: The CJS build of Vite's Node API is deprecated.
node@568664e019fc:/workspaces/react-router-sample$ npm run dev
> dev
> react-router dev
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.
➜ Local: http://127.0.0.1:5173/
➜ press h + enter to show help
This warning indicates that the CJS build of Vite's Node API has been deprecated, but type in package.json was already set to module.
Upon investigation, I found that it occurs depending on the minor version of Node.js. I was using Node v20, and the results were as follows:
-
v20.15.1× Warning occurs -
v20.16.0× -
v20.17.0× -
v20.18.3× -
v20.19.3〇 No warning
node@568664e019fc:/workspaces/react-router-sample$ node -v
v20.19.3
node@568664e019fc:/workspaces/react-router-sample$ npm run dev
> react-router-sample@ dev /workspaces/react-router-sample
> react-router dev
➜ Local: http://127.0.0.1:5173/
➜ press h + enter to show help
Since require(esm) became enabled in v20.19, that might be what changed things. (Though one could argue I should just use v22 or v24...)
I'm leaving this here in case anyone else runs into the same issue.
Discussion