为什么在我运行npm run start时npm react-scripts会产生语法错误?

时间:2019-02-11 01:54:55

标签: javascript reactjs npm npm-start react-scripts

所以我已经在全栈React应用程序上工作了几个月了。由于某种原因,当我尝试在命令行上运行npm run start时,似乎无处不在,它产生了以下错误;

// npm run start

> pair@0.1.0 start /Users/eden/Documents/GitHub/Pair./pair
> react-scripts start

/Users/eden/Documents/GitHub/Pair./pair/node_modules/react-dev-utils/WebpackDevServerUtils.js:166
  compiler.hooks.done.tap('done', async stats => {
                                  ^^^^^

SyntaxError: missing ) after argument list
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/eden/Documents/GitHub/Pair./pair/node_modules/react-scripts/scripts/start.js:45:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! pair@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the pair@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!     /Users/eden/.npm/_logs/2019-02-11T01_36_36_244Z-debug.log

我尝试了以下方法;

  • 卸载/重新安装节点
  • 卸载/重新安装npm
  • 确保node和npm为6或更高版本
  • 删除node_modulespackage-lock.json并重新运行npm-i
  • 卸载/重新安装react-scripts
  • 降级反应脚本
  • 运行npm install --save react react-dom react-scripts
  • 卸载/重新安装react-dev-utils

我什至尝试将GitHub homepage of react-dev-utilsWebpackDevServerUtils.js的内容复制/粘贴到本地node_modules/react-dev-utils/WebpackDevServerUtils.js中以解决语法错误。

我不知道为什么会这样。下面是该运行的日志;

0 info it worked if it ends with ok
1 verbose cli [ '/Users/eden/.nvm/versions/node/v6.11.2/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'run',
1 verbose cli   'start' ]
2 info using npm@6.4.1
3 info using node@v6.11.2
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle pair@0.1.0~prestart: pair@0.1.0
6 info lifecycle pair@0.1.0~start: pair@0.1.0
7 verbose lifecycle pair@0.1.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle pair@0.1.0~start: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/eden/Documents/GitHub/Pair./pair/node_modules/.bin:/Users/eden/.nvm/versions/node/v6.11.2/bin:/Applications/Postgres.app/Contents/Versions/latest/bin:/usr/local:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/eden/.rvm/bin
9 verbose lifecycle pair@0.1.0~start: CWD: /Users/eden/Documents/GitHub/Pair./pair
10 silly lifecycle pair@0.1.0~start: Args: [ '-c', 'react-scripts start' ]
11 silly lifecycle pair@0.1.0~start: Returned: code: 1  signal: null
12 info lifecycle pair@0.1.0~start: Failed to exec start script
13 verbose stack Error: pair@0.1.0 start: `react-scripts start`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at emitTwo (events.js:106:13)
13 verbose stack     at EventEmitter.emit (events.js:191:7)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:106:13)
13 verbose stack     at ChildProcess.emit (events.js:191:7)
13 verbose stack     at maybeClose (internal/child_process.js:891:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
14 verbose pkgid pair@0.1.0
15 verbose cwd /Users/eden/Documents/GitHub/Pair./pair
16 verbose Darwin 18.2.0
17 verbose argv "/Users/eden/.nvm/versions/node/v6.11.2/bin/node" "/usr/local/bin/npm" "run" "start"
18 verbose node v6.11.2
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error pair@0.1.0 start: `react-scripts start`
22 error Exit status 1
23 error Failed at the pair@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 [ 1, true ]

我查看了WebpackDevServerUtils.js的第166行,并使用ESLint来标识语法错误,但找不到任何东西。

因此,我的问题是:如何解决这个晦涩的错误?

1 个答案:

答案 0 :(得分:2)

该错误似乎与异步有关,并且您正在使用不支持异步/等待的节点6。更新到支持该节点的最新版本(7.6),您应该会很好。