35012

Nodejs npm scripts fail with “SyntaxError: Unexpected token {”

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

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

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

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

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

Any help is appreciated.

Answer1:

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

You have two options:

<ol> <li>Install a newer version of Node.js</li> <li>Run node with the harmony flags that will enable this feature in version 4.x.</li> </ol>

Recommend

  • Error while running a new created React JS app in WebStorm
  • Most middleware (like compress) is no longer bundled with .. ERROR
  • webpack-dev-server Cannot find module 'webpack'
  • Does require in node uses eval to run a code in another file
  • EF Migration migrate to 0 call initial creates down
  • What object to pass to R from rpy2?
  • configure babel with WebStorm to use ES6 with WebStorm Node.js project
  • Angular AOT failing at compilation (something with angular/compiler-cli)
  • Installing ngpsql to use PostgreSQL in PowerBI
  • ruby on rails TypeError in Users#show - Cannot visit Like
  • Angularjs hide and show according to screen size responsive
  • yii2 create translated URLs
  • Laravel phpunit always 404
  • An unexpected error has been detected by HotSpot Virtual Machine
  • Getting zero results in search using elastic4s
  • RPMs for IDAS IoTAgents GE, from Fiware
  • IDX10503: Signature validation failed
  • oauth2client.client.HttpAccessTokenRefreshError: invalid_grant: Invalid JWT
  • Syntax error near unexpected token 'elif'
  • Can't resolve 'jquery' with typescript
  • php show all images in directory and sort by last modified
  • SQL getting multiple columns into one column
  • Relative paths. baseUrl and paths not working on ionic2 - angular2
  • read values from form post in jquery or javascript
  • Connecting bluetooth device to windows phone 8 application
  • passing a default argument to a browserify module
  • CXF JAXB JAXBEncoderDecoder unmarshalling error : unexpected element when having qualified elements
  • Unexpected token ILLEGAL while running node.js mocha test
  • Autofac with Web API 2 - Parameter-less constructor error
  • pillow imaging ImportError
  • Authentication in Play! and RestEasy
  • Django simple Captcha “No module named fields” error
  • How do I exclude a dependency in provided scope when running in Maven test scope?
  • Is there a perl module to validate passwords stored in “{crypt}hashedpassword” “{ssha}hashedpassword
  • Meteor helpers not available in Angular template
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • Pass value from viewmodel to script in zk
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Error creating VM instance in Google Compute Engine
  • using HTMLImports.whenReady not working in chrome