10

所以几个月来我一直在开发一个完整的 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
  • 卸载/重新安装反应脚本
  • 降级反应脚本
  • 跑步npm install --save react react-dom react-scripts
  • 卸载/重新安装 react-dev-utils

WebpackDevServerUtils.js我什至尝试将 react-dev-utils的GitHub 主页中的内容复制/粘贴到我的本地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 来识别语法错误,但找不到任何东西。

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

4

1 回答 1

16

错误似乎在异步上,您使用的是不支持异步/等待的节点 6。更新到支持它的最新版本的节点(7.6),你应该很好。

于 2019-02-13T13:32:09.933 回答