安装错误:npm install -g create-react-app。

4

我正在Udemy上学习“现代React与Redux课程”,教练要求先安装NodeJs,然后安装“npm install -g create-react-app”,当我尝试运行这个命令时,出现了错误:-

npm install -g create-react-app
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/nitintushir/.npm/_logs/2019-09-20T15_22_12_437Z-debug.log

然后我在Stack Overflow上看到一些问题,有人建议运行以下命令:-

 npm cache clean --force

我得到的结果是:


npm WARN using --force I sure hope you know what you are doing.

然后我运行了这个。
npm install -g create-react-app

命令再次输入,但仍然出现相同的错误,请问有解决方案/建议吗?

可能是重复的问题,与 https://dev59.com/T1sX5IYBdhLWcg3wf_v3 相似。 - Naga Sai A
2个回答

2
你应该使用nvm来管理你的node和npm版本。 https://github.com/nvm-sh/nvm 这将允许你在不需要sudo权限的情况下全局安装node模块。
同时,你也可以通过nvm CLI随时更改你的node版本。

2

看起来像是访问权限错误,您应该尝试以root身份运行安装程序,如下所示:

sudo npm install -g create-react-app

谢谢 @Saxtheowl。它对我有用。输出:'+ create-react-app@3.1.2' '从45位贡献者中添加了91个软件包,用时66.878秒'。 - Nitin Tushir

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接