我是 React 新手,我一直在尝试开始我的新项目。当我运行“npm start”时,出现以下错误:
'CALL "C:\Program Files\nodejs\\node.exe" "C:\Program Files\nodejs\\node_modules\npm\bin\npm-cli.js" prefix -g' is not recognized as an internal or external command, operable program or batch file.
> reactproject@1.0.0 start C:\React\reactProject
> npm run build
npm ERR! file C:\Windows\system32\
npm ERR! path C:\Windows\system32\
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn C:\Windows\system32\
npm ERR! reactproject@1.0.0 start: `npm run build`
npm ERR! spawn C:\Windows\system32\ ENOENT
npm ERR!
npm ERR! Failed at the reactproject@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! code ELIFECYCLE
npm ERR! errno -4058
npm ERR! reactproject@1.0.0 start: `npm run build`
npm ERR! Exit status -4058
npm ERR!
npm ERR! Failed at the reactproject@1.0.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! C:\Users\steve\AppData\Roaming\npm-cache\_logs\2017-09-01T09_33_35_096Z-debug.log
这是我的 package.json:
{
"name": "reactproject",
"version": "1.0.0",
"description": "ReactJS project",
"main": "index.js",
"scripts": {
"start": "npm run build",
"build": "webpack -d && xcopy \"src/index.html\" \"dist/\" /F /Y && webpack-dev-server --content-base src/ --inline",
"build:prod": "webpack -p && xcopy \"src/index.html\" \"dist/\" /F /Y"
},
"keywords": [
"reactjs"
],
"author": "author",
"license": "MIT",
"dependencies": {
"react": "^15.6.1",
"react-dom": "^15.6.1"
},
"devDependencies": {
"babel-core": "^6.26.0"
}
}
和调试日志:
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'start' ]
2 info using npm@5.3.0
3 info using node@v8.4.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle reactproject@1.0.0~prestart: reactproject@1.0.0
6 info lifecycle reactproject@1.0.0~start: reactproject@1.0.0
7 verbose lifecycle reactproject@1.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle reactproject@1.0.0~start: PATH: C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;C:\React\reactProject\node_modules\.bin;C:\Program Files\Java\jre1.8.0_121\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\nodejs\;C:\Users\steve\AppData\Local\Microsoft\WindowsApps;C:\Users\steve\AppData\Roaming\npm
9 verbose lifecycle reactproject@1.0.0~start: CWD: C:\React\reactProject
10 silly lifecycle reactproject@1.0.0~start: Args: [ '/d /s /c', 'npm run build' ]
11 info lifecycle reactproject@1.0.0~start: Failed to exec start script
12 verbose stack Error: reactproject@1.0.0 start: `npm run build`
12 verbose stack spawn C:\Windows\system32\ ENOENT
12 verbose stack at _errnoException (util.js:1041:11)
12 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
12 verbose stack at onErrorNT (internal/child_process.js:374:16)
12 verbose stack at _combinedTickCallback (internal/process/next_tick.js:138:11)
12 verbose stack at process._tickCallback (internal/process/next_tick.js:180:9)
13 verbose pkgid reactproject@1.0.0
14 verbose cwd C:\React\reactProject
15 verbose Windows_NT 10.0.14393
16 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
17 verbose node v8.4.0
18 verbose npm v5.3.0
19 error file C:\Windows\system32\
20 error path C:\Windows\system32\
21 error code ELIFECYCLE
22 error errno ENOENT
23 error syscall spawn C:\Windows\system32\
24 error reactproject@1.0.0 start: `npm run build`
24 error spawn C:\Windows\system32\ ENOENT
25 error Failed at the reactproject@1.0.0 start script.
25 error This is probably not a problem with npm. There is likely additional logging output above.
26 verbose exit [ 1, true ]
我试过用谷歌搜索类似的问题,但我发现的唯一建议是更改脚本(我做了)并安装 babel-core。另外,我运行了“npm run build”而不是“npm start”,但仍然出现同样的错误。
我怀疑问题可能出在环境变量(路径错误)上,但即使我是对的,我也不知道如何解决它。
感谢您的任何回复。