我已经安装了 node.js,在使用以下命令时收到错误:
create-react-app <folder name>
输出为:
Creating a new React app in C:\Users\Desktop\my-react-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
> [email protected] postinstall C:\Users\Desktop\my-react-app\n
ode_modules\uglifyjs-webpack-plugin
> node lib/post_install.js
npm ERR! path C:\Users\Desktop\my-react-app\node_modules\nan\package.json
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall unlink
npm ERR! Error: EPERM: operation not permitted, unlink 'C:\Users\Desktop\my
-react-app\node_modules\nan\package.json'
npm ERR! at Error (native)
npm ERR! { Error: EPERM: operation not permitted, unlink 'C:\Users\Desktop
\my-react-app\node_modules\nan\package.json'
npm ERR! at Error (native)
npm ERR! stack: 'Error: EPERM: operation not permitted, unlink \'C:\\Users\\Desktop\\my-react-app\\node_modules\\nan\\package.json\'\n at Error (nati
ve)',
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'unlink',
npm ERR! path: 'C:\\Users\\Desktop\\my-react-app\\node_modules\\nan\\pac
kage.json' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\AppData\Roaming\npm-cache\_logs\2017-09-07T11_17_31_8
99Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts
has failed.
Deleting generated file... node_modules
Deleting generated file... package.json
Deleting my-react-app / from C:\Users\Desktop
Done.
以管理员身份运行时问题仍然存在:
Your environment has been set up for using Node.js 6.11.3 (x64) and npm.
C:\Windows\System32>npm install -g create-react-app
C:\Users\amar\AppData\Roaming\npm\create-react-app -> C:\Users\amar\AppData\R
ing\npm\node_modules\create-react-app\index.js
+ [email protected]
updated 1 package in 17.296s
C:\Windows\System32>create-react-app react-app
Creating a new React app in C:\Windows\System32\react-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
> [email protected] postinstall C:\Windows\System32\react-app\nod
odules\uglifyjs-webpack-plugin
> node lib/post_install.js
npm ERR! path C:\Windows\System32\react-app\node_modules\nan\package.json
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall unlink
npm ERR! Error: EPERM: operation not permitted, unlink 'C:\Windows\System32\r
t-app\node_modules\nan\package.json'
npm ERR! at Error (native)
npm ERR! { Error: EPERM: operation not permitted, unlink 'C:\Windows\System3
eact-app\node_modules\nan\package.json'
npm ERR! at Error (native)
npm ERR! stack: 'Error: EPERM: operation not permitted, unlink \'C:\\Window
System32\\react-app\\node_modules\\nan\\package.json\'\n at Error (native)
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'unlink',
npm ERR! path: 'C:\\Windows\\System32\\react-app\\node_modules\\nan\\packag
son' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\amar\AppData\Roaming\npm-cache\_logs\2017-09-07T17_16_1
06Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scri
has failed.
Deleting generated file... node_modules
Deleting generated file... package.json
Deleting react-app / from C:\Windows\System32
Done.
C:\Windows\System32>
答案1
遗憾的是,您遗漏了路径 – 这可能是罪魁祸首。
此错误消息表明 npm 没有执行某些文件操作的权限:
npm ERR! Please try running this command again as root/Administrator.
这可能在运行时npm install -g <something>
(全局安装某些东西)发生,但对于本地安装,这通常表示路径有错误。
确实,第二行的路径看起来不对:
Creating a new React app in C:\Users\Desktop\my-react-app.
您的用户名缺失!C:\Users
包含用户配置文件,其中包含Desktop
文件夹。因此路径应该是C:\Users\
YourUsername
\Desktop\my-react-app
。