Nodejs npm 脚本失败并显示“SyntaxError: Unexpected token {"; [英] Nodejs npm scripts fail with "SyntaxError: Unexpected token {"

查看:39
本文介绍了Nodejs npm 脚本失败并显示“SyntaxError: Unexpected token {";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将我的 Reactjs 项目导入到 Ubuntu 上的新机器,并使用 npm install 成功安装了大多数依赖项,如下所示:

I've just imported my Reactjs project to a new machine on Ubuntu and installed most dependencies with npm install successfully bar the following:

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

尝试使用 npm start 运行项目失败:

Trying to run the project with npm start fails with:

> 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

尝试运行包括 npm run build 在内的任何 npm 脚本都失败,并出现完全相同的错误,引用 SyntaxError 中每个文件中的相同行:

Attempting to run any npm script including npm run build all fails with the exact same error referencing the same lines in each file in the 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

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

Running the same scripts on my original machine, a Mac, succeed.

我试过重新安装 node/npm ,但没有解决问题.所谓的可选依赖是否会导致此失败?

I've tried re-installing node/npm which do not fix the issue. Is the supposedly optional dependency causing this to fail?

感谢任何帮助.

推荐答案

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

You're using node.js v4 which does not by default support destructuring syntax (the const {field1, field2, ....} = object) that it is failing on.

您有两个选择:

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

这篇关于Nodejs npm 脚本失败并显示“SyntaxError: Unexpected token {";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆