npm create-react-app错误:EACCES:权限被拒绝。 操作被您的操作系统拒绝。

3

我想在vscode中使用react,但是当我尝试安装node.js时,它会出现错误。我的命令是

npm install -g create-react-app

npm ERR! code EACCES
npm ERR! syscall symlink
npm ERR! path ../lib/node_modules/create-react-app/index.js
npm ERR! dest /usr/local/bin/create-react-app
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/create-react-app/index.js' -> '/usr/local/bin/create-react-app'
npm ERR!  [OperationalError: EACCES: permission denied, symlink '../lib/node_modules/create-react-app/index.js' -> '/usr/local/bin/create-react-app'] {
npm ERR!   cause: [Error: EACCES: permission denied, symlink '../lib/node_modules/create-react-app/index.js' -> '/usr/local/bin/create-react-app'] {
npm ERR!     errno: -13,
npm ERR!     code: 'EACCES',
npm ERR!     syscall: 'symlink',
npm ERR!     path: '../lib/node_modules/create-react-app/index.js',
npm ERR!     dest: '/usr/local/bin/create-react-app'
npm ERR!   },
npm ERR!   stack: "Error: EACCES: permission denied, symlink '../lib/node_modules/create-react-app/index.js' -> '/usr/local/bin/create-react-app'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'symlink',
npm ERR!   path: '../lib/node_modules/create-react-app/index.js',
npm ERR!   dest: '/usr/local/bin/create-react-app'
npm ERR! }
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.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/defneyazicioglu/.npm/_logs/2020-03-23T17_10_48_130Z-debug.log

我该如何解决这个问题?

只需从命令中删除“-g”。您不需要全局安装“create-react-app”。 - shyammakwana.me
错误是因为您没有权限。 - shyammakwana.me
使用sudo npm install -g create-react-app - prabhu
1
这基本上是因为您的用户没有全局安装npm模块的访问权限。我知道有两种解决方法。1.使用Sudo安装模块。例如 sudo npm install -g create-react-app 或者 2. 您可以在没有root访问权限的情况下安装node js。从这里找到更多信息:https://medium.com/@nadun1indunil/do-not-sudo-npm-why-5b9adff8caa2。 - Nadun
1个回答

3

尝试使用以下命令:

  1. $sudo -s
  2. $npm install -g create-react-app
  3. $exit
  4. $npx create-react-app my-app

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