我知道这个问题以前已经发生在很多人身上很多次了,但我昨天花了几个小时试图解决这个问题,我一辈子都想不出来。
我正在尝试学习React,当我尝试使用";npm启动";命令,它是这样的:
$ npm start
> react-app@0.1.0 start /react-app
> /react-app/node_modules/react-scripts/scripts/start.js
sh: 1: /react-app/node_modules/react-scripts/scripts/start.js: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! react-app@0.1.0 start: `/react-app/node_modules/react-scripts/scripts/start.js`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the react-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/sven/.npm/_logs/2020-12-13T06_45_28_430Z-debug.log
我尝试过的东西:
- 将执行权限添加到";"开始";脚本
- 删除所有节点模块,重新安装节点,重新创建项目文件
- 编辑package.json以包含启动脚本
在我使用的教程中,这个家伙只需输入npm start
,它就可以正常工作。如果有什么不同的话,有人能解释一下npm start
在这种情况下的作用吗?在这一点上我真的不知道该怎么办。
这就是我的package.json的样子:
{
"name": "react-app",
"version": "0.1.0",
"private": true,
"scripts": {
"start": "/home/sven/react-app/node_modules/react-scripts/scripts/start.js"
},
"dependencies": {
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.1"
}
}
这是日志文件:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ]
2 info using npm@6.14.4
3 info using node@v10.19.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle react-app@0.1.0~prestart: react-app@0.1.0
6 info lifecycle react-app@0.1.0~start: react-app@0.1.0
7 verbose lifecycle react-app@0.1.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle react-app@0.1.0~start: PATH: /usr/share/npm/node_modules/npm-lifecycle/node-gyp-bin:/react-app/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle react-app@0.1.0~start: CWD: /react-app
10 silly lifecycle react-app@0.1.0~start: Args: [ '-c',
10 silly lifecycle '/react-app/node_modules/react-scripts/scripts/start.js' ]
11 silly lifecycle react-app@0.1.0~start: Returned: code: 126 signal: null
12 info lifecycle react-app@0.1.0~start: Failed to exec start script
13 verbose stack Error: react-app@0.1.0 start: `/react-app/node_modules/react-scripts/scripts/start.js`
13 verbose stack Exit status 126
13 verbose stack at EventEmitter.<anonymous> (/usr/share/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:198:13)
13 verbose stack at ChildProcess.<anonymous> (/usr/share/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:198:13)
13 verbose stack at maybeClose (internal/child_process.js:982:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid react-app@0.1.0
15 verbose cwd /react-app
16 verbose Linux 5.4.0-58-generic
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "start"
18 verbose node v10.19.0
19 verbose npm v6.14.4
20 error code ELIFECYCLE
21 error errno 126
22 error react-app@0.1.0 start: `/react-app/node_modules/react-scripts/scripts/start.js`
22 error Exit status 126
23 error Failed at the react-app@0.1.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 126, true ]
我也遇到了这个问题。这是因为REACT PROJECT根文件夹存在权限问题。当CCD_ 3或CCD_。react应用程序将被构建,它需要创建名为"的目录;构建";在react项目目录中。请尝试使用
sudo chmod 777 {/path/dir_name}
它对我有效。最后确保更新";npm";全球。