4

I want to try React on my Mac, but I face some difficulties when using it.

  1. I installed create-react-app globally with

    npm install -g create-react-app

But everytime I create a new project I have a huge node_modules folder in my project folder. AFAIK I don't need node_modules folder in every project if create-react-app installed globally. So what's the problem?

  1. When I tried to uninstall create-react-app to install it again (just to be sure I installed it globally) I get an error saying

    npm remove -g create-react-app

    Error: EACCES: permission denied, unlink 'usr/local/bin/create-react-app'

So what do I do in this case?

AndSolomin34
  • 399
  • 4
  • 12
  • Possible duplicate of [How to uninstall npm modules in node js?](https://stackoverflow.com/questions/13066532/how-to-uninstall-npm-modules-in-node-js) – josephting Mar 27 '19 at 08:31

5 Answers5

5
  1. The node_modules folder you see for every project is node_modules for that specific project. This is how all javascript projects that use npm work. You don't want all the dependencies of every project installed globally. That would run into all kinds of issues with different versions of packages etc.
  2. This error indicates that you probably ran npm install -g create-react-app as either root or as sudo like so: sudo npm install -g create-react-app. Try running sudo npm remove -g create-react-app and see if that works.
Marius
  • 1,053
  • 2
  • 7
  • 16
  • but could you please watch [this video](https://www.youtube.com/watch?v=0grybmrgc2Q&t=208s) (starts at 5:00). I do the same steps that guy does, but he doesn't have node_modules in his project – AndSolomin34 Mar 27 '19 at 08:39
  • @AndSolomin34 If you watch the video, at exactly 5.10, he shows the contents of cities folder and first folder in it is node_modules. – PrivateOmega Mar 27 '19 at 08:57
  • @KiranMathewMohan i'm so sorry, I just didn't see it in Atom list of files – AndSolomin34 Mar 27 '19 at 09:02
  • @AndSolomin34 No issues. Mark the correct answer so no one else would try to attempt an already answered question. – PrivateOmega Mar 27 '19 at 09:07
4

I couldn't use the new version of create-react-app with npx, so I tried to remove via the command npm uninstall -g create-react-app. After that when I checked it still has "installed". So I have removed manually

rm -rf /usr/local/bin/create-react-app
Gapur Kassym
  • 1,131
  • 12
  • 10
2

But everytime I create a new project I have a huge node_modules folder in my project folder.

That node_modules folder store all the local dependencies for that particular project with specific versions as mentioned in package.json and its dependencies also. It is required for every project, unless all dependencies of your project are global and match the versions perfectly which never would be the case AFAIK.

Use npm uninstall -g package_name for removing package.

Also its better if you use npx for create new react projects. But this would only work properly if npm version is above 5 and you have to uninstall global create-react-app first.

npx create-react-app my-app 
PrivateOmega
  • 2,509
  • 1
  • 17
  • 27
0

I hard similar issue with mine. I did

npm uninstall -g create-react-app 

and it worked.

Red
  • 26,798
  • 7
  • 36
  • 58
sideeq12
  • 21
  • 1
  • 3
0

this may sound odd but it work many times if this kind of error come than run code in your terminal

npm uninstall -g create-react-app 

if not work than without any headache run

 npm i create-react-app

in your root folder this will update the react app in your system after this untill next latest version you can enjoy with

npx i create-react-app my-app
vibhu
  • 369
  • 3
  • 10