Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@vitejs/plugin-react'

There is this problem with render, i have my project set up and running perfectly fine on localhost, every dependency works as expected. But when i try to deploy this project here on render i am getting this error that the module not found.
It says that frontend>vite.config.js

error during build:

May 9 10:33:31 AMError [ERR_MODULE_NOT_FOUND]: Cannot find package ‘@vitejs/plugin-react’ imported from /opt/render/project/src/frontend/vite.config.js.timestamp-1715231011704-ba74b004efb23.mjs

I have everything pushed on my github i have checked it multiple times, everything is present inside the devDependencies, now why is render giving this error. Can i get a solution it been a day since i am stuck here on this error

Hi there,

Note that if NODE_ENV is set to production npm will not install devDependencies: https://docs.npmjs.com/cli/v10/commands/npm-install

Regards,

Keith
Render Support, UTC+10 :australia:

1 Like


why i explicitly did that was because if I keep NODE_ENV to development and try to run build and then try npm run start the mern app gives no output. it says Cannot GET/
But when i set to production and then run then it works on localhost but i see now what’s the issue setting it to production it wont download node modules.

So now how should i solve this above is the folder structure. one for backend and frontend.
node modules for backend is outside as u see now i wanted to just build and run this application. but it is not working .

I have been stuck on this, and I appreciate your help.
Thank you

Hi there,

You should set it to production, but anything you need to build and run on Render should be included in your dependencies, not devDependencies.

If you want to have dependencies installed at build time but then removed for runtime you could do something like npm install --include=dev && npm run build && npm prune. With NODE_ENV set to production, this will install your devDependencies but prune them at the end of the build. However, do note there is a drawback to doing this. At the end of the build we cache your node_modules folder, but because your devDependencies are pruned they don’t get cached and thus will be downloaded every build.

I would probably just use the first option.

Regards,

Keith
Render Support, UTC+10 :australia: