【问题标题】:Error in installing :- npm install -g create-react-app安装时出错:- npm install -g create-react-app
【发布时间】:2020-01-21 16:38:26
【问题描述】:

我在 Udemy 上学习“Modern React with Redux Course”,讲师要求先安装 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

然后我在stackoverflow上遇到了一些问题,有人建议运行这个命令:-

 npm cache clean --force

我得到的:

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

然后我运行

npm install -g create-react-app

再次命令,但仍然出现同样的错误,有什么解决方案/建议吗?

【问题讨论】:

标签: reactjs npm


【解决方案1】:

这看起来像是一个访问权限错误,您应该尝试以 root 身份运行您的安装:

sudo npm install -g create-react-app

【讨论】:

  • 谢谢 @Saxtheowl 。它对我有用。输出:- '+ create-react-app@3.1.2' '在 66.878 秒内添加了来自 45 个贡献者的 91 个包'
【解决方案2】:

您应该使用 nvm 来管理您的节点和 npm 版本。 https://github.com/nvm-sh/nvm

这将允许您在没有任何 sudo 权限的情况下全局安装节点模块

您还可以随时使用 nvm CLI 更改节点版本

【讨论】:

    猜你喜欢
    • 2021-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-27
    • 2020-12-19
    • 2018-10-29
    • 2017-02-18
    相关资源
    最近更新 更多