Search code examples
node.jsreactjsnpmcreate-react-app

Need to delete node_modules every time a new package is installed in React


We've recently started working on a project with create-react-app, but whenever someone adds a new package and commits those changes, we have to delete node_modules and install them again, even though we used yarn install.

What happens is, if I add one package, let's say "yarn add uuid" and commit both yarn.lock and package.json, when another dev pulls those changes and runs "yarn", it "installs" everything, and when he/she runs "yarn start" it will complain "Cannot find module 'uuid'". Even when they add again "yarn add uuid", when they run "yarn start" it'll complain again. The solution we saw was to delete node_modules and run "yarn install" again, but we have to do it every time.

I've never faced it before, I even thought it was something to do with my computer, but we're three devs facing the same problem.

We're using node v14.18.1, yarn 1.22.17 and react-scripts 4.0.3 we're all using yarn, I even added only-allow to only allow yarn


Solution

  • I could solve this problem by updating react-scripts ^5, they've upgraded the webpack version and I think it did the trick.