javascript - Nodejs npm 脚本失败并显示 "SyntaxError: Unexpected token {"

标签 javascript node.js ubuntu 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

尝试使用 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

尝试运行任何 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

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

我已经尝试重新安装 node/npm,但没有解决问题。假定的可选依赖项是否导致此失败?

感谢任何帮助。

最佳答案

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

你有两个选择:

  1. 安装更新版本的 Node.js
  2. 使用将在版本 4.x 中启用此功能的和谐标志运行 Node 。

关于javascript - Nodejs npm 脚本失败并显示 "SyntaxError: Unexpected token {",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45108189/

相关文章:

javascript - 日期和随机数如何在 Javascript 中用于作恶?

javascript - 如何在 JavaScript 中实现一组字母(小写和大写)的排列生成器(或内存函数)?

javascript - 无论如何,有没有办法实现带有 2 个国家国旗和一些文本的卡片,我正在使用带有 expo 的 React-native-element 库

javascript - 作为一个整体解析具有 promise 属性的对象的更好方法?

node.js - 使用 node.js 将视频上传到 youtube

.htaccess - 使用 .htaccess 的 http 到 https 重定向不起作用

javascript - Google 我的 map 到 Google map API

javascript - 无法设置 Node 和express来提供文件

linux - 更新Xubuntu依赖

linux - Ubuntu 12.04 将现有用户添加到组