首页 > 解决方案 > create-react-app newproject 命令行对我不起作用

问题描述

由于某种原因,当我输入 create-react-app newproject 命令时,我以“找不到命令”告终。它一直给我这个错误:

npm WARN checkPermissions Missing write access to /Users/kennyquach/.npm-global/lib/node_modules/create-react-app
npm ERR! path /Users/kennyquach/.npm-global/lib/node_modules/create-react-app
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/Users/kennyquach/.npm-global/lib/node_modules/create-react-app'
npm ERR!  { Error: EACCES: permission denied, access '/Users/kennyquach/.npm-global/lib/node_modules/create-react-app'
npm ERR!   stack: 'Error: EACCES: permission denied, access \'/Users/kennyquach/.npm-global/lib/node_modules/create-react-app\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/Users/kennyquach/.npm-global/lib/node_modules/create-react-app' }
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/kennyquach/.npm/_logs/2018-11-28T17_50_32_739Z-debug.log

任何帮助表示赞赏!谢谢!

标签: javascriptnode.jsreactjsreact-native

解决方案


您很可能使用 Mac OS 作为操作系统。这是 MacOS 中全局安装包的普遍问题,由内置节点应用程序的文件权限引起。实际上你可以通过create-react-approot身份执行来克服这个问题,但我不建议这样做,它没有用而且有风险。

所以你有2个选择。(第一个难做,第二个火爆)

1-) 从您的系统中完全删除 Node 并使用Brew安装它。您可以使用该包管理器轻松更新节点并安装任何其他流行的开发工具(例如:mongodb、mysql、pgsql、rabbitmq 等)。您可以从此处获取 brew:https ://brew.sh并使用该代码安装节点:brew install node

2-) 您可以轻松地授予对您的文件夹和文件的读取、写入、执行访问权限。您可以这样做:sudo chmod -R 777 /Users/kennyquach/.npm-global/当 sudo 询问您的密码时,请使用您的管理员密码。


推荐阅读