Nodejs npm脚本失败,出现"SyntaxError:Unexpected token {"

Shi*_*iri 4 javascript ubuntu node.js npm-scripts

我刚刚将我的Reactjs项目导入Ubuntu上的新机器并安装了大多数依赖项,并npm install成功地禁用了以下内容:

npm WARN optional Skipping failed optional dependency /react-scripts/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.17
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.1.2
Run Code Online (Sandbox Code Playgroud)

尝试运行项目时npm start失败:

> booking-frontend@0.1.0 start /root/17-visit-booker-frontend
> react-scripts start


/root/17-visit-booker-frontend/node_modules/react-scripts/scripts/start.js:33
const {
      ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)
    at node.js:966:3

npm ERR! Linux 4.4.0-81-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "start"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! booking-frontend@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the booking-frontend@0.1.0 start script 'react-scripts start'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the booking-frontend package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     react-scripts start
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs booking-frontend
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls booking-frontend
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /root/17-visit-booker-frontend/npm-debug.log
Run Code Online (Sandbox Code Playgroud)

尝试运行npm包含npm run build所有脚本的任何脚本失败,并且在SyntaxError中引用每个文件中的相同行完全相同的错误:

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)
    at node.js:966:3
Run Code Online (Sandbox Code Playgroud)

在我的原始机器上运行相同的脚本,Mac,成功.

我已经尝试重新安装node/ npm不解决问题.是否可选的依赖导致此失败?

任何帮助表示赞赏.

小智 6

您正在使用node.js v4,它默认情况下不支持const {field1, field2, ....} = object失败的解构语法().

您有两种选择:

  1. 安装较新版本的Node.js.
  2. 使用和声标志运行节点,该标志将在版本4.x中启用此功能.