pd4d10 / vite-plugin-svgr

Vite plugin to transform SVGs into React components
MIT License
565 stars 54 forks source link

Need To Use Plugin with Vite Version 4.0 #122

Open DragonOsman opened 4 months ago

DragonOsman commented 4 months ago

I have a MERN app I'm trying to deploy to Glitch, which only supports Node up to version 16.x. I want to switch from CRA to Vite in my project, but I'm having dependency resolution issues in NPM.

Here are the messages with the commands I ran:

npm install vite @vitejs/plugin-react-swc vite-tsconfig-paths vite-plugin-svgr
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: vite@5.3.3
npm ERR! Found: @types/node@16.18.34
npm ERR! node_modules/@types/node
npm ERR!   @types/node@"^16.18.34" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional @types/node@"^18.0.0 || >=20.0.0" from vite@5.3.3
npm ERR! node_modules/vite
npm ERR!   vite@"*" from the root project
npm ERR!   peer vite@"^4 || ^5" from @vitejs/plugin-react-swc@3.7.0
npm ERR!   node_modules/@vitejs/plugin-react-swc
npm ERR!     @vitejs/plugin-react-swc@"*" from the root project
npm ERR!   2 more (vite-plugin-svgr, vite-tsconfig-paths)
npm ERR!
npm ERR! Conflicting peer dependency: @types/node@20.14.10
npm ERR! node_modules/@types/node
npm ERR!   peerOptional @types/node@"^18.0.0 || >=20.0.0" from vite@5.3.3
npm ERR!   node_modules/vite
npm ERR!     vite@"*" from the root project
npm ERR!     peer vite@"^4 || ^5" from @vitejs/plugin-react-swc@3.7.0
npm ERR!     node_modules/@vitejs/plugin-react-swc
npm ERR!       @vitejs/plugin-react-swc@"*" from the root project
npm ERR!     2 more (vite-plugin-svgr, vite-tsconfig-paths)
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\Osman\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Osman\AppData\Local\npm-cache\_logs\2024-07-10T19_38_55_919Z-debug-0.log

Then, after that:

npm install vite@4.0.0  @vitejs/plugin-react-swc@2.0.0 vite-tsconfig-paths@4.0.0 vite-plugin-svgr@2.0.0
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: client@0.1.0
npm ERR! Found: vite@4.0.0
npm ERR! node_modules/vite
npm ERR!   vite@"4.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer vite@"^2.6.0" from vite-plugin-svgr@2.0.0
npm ERR! node_modules/vite-plugin-svgr
npm ERR!   vite-plugin-svgr@"2.0.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\Osman\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Osman\AppData\Local\npm-cache\_logs\2024-07-10T20_23_26_936Z-debug-0.log

So, with that context, I guess my question should be: what exact versions of each package should I use? I want to avoid running the command with the `--legacy-peer-deps" flag if possible.

Sorry if this isn't a question to ask here. And thanks in advance for any help or advice.

Edit to further clarify: I'm using Windows 10, and I installed NVM for Windows to be able to switch between the latest LTS version of Node and version 16.

cavalloTNguyen commented 3 months ago

If you're running in a Node 16 environment, you'll have to use Vite 4.x; Vite 5.x does not support Node 16 anymore.

https://vitejs.dev/blog/announcing-vite5#node-js-support

I don't think you should run into any problems downgrading to vite 4.x

If you specify just the major version, your installer should resolve the minor and patch versions to latest, ie, npm i vite@4

revelt commented 6 days ago

@DragonOsman can we close this issue?