nuxt: SyntaxError: Unexpected token ...

NuxtJS version 1.4.0 When using https://github.com/nuxt-community/starter-template, on npm run dev I got

\test\node_modules\nuxt\lib\core\middleware\nuxt.js:72
      const policies = this.options.render.csp.policies ? {...this.options.render.csp.policies} : null
                                                           ^^^

SyntaxError: Unexpected token ...
    at createScript (vm.js:74:10)
    at Object.runInThisContext (vm.js:116:10)
    at Module._compile (module.js:533:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (\test\node_modules\nuxt\lib\core\renderer.js:19:24)

NuxtJS 1.3.0 works correctly. Probably https://github.com/nuxt/nuxt.js/commit/a403205abe7e5c036c8aa3ee535e44c225ff2082 broken this

<div align="right">This question is available on Nuxt.js community (#c2541)</div>

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 32 (4 by maintainers)

Most upvoted comments

I had this same issue when using Node 8.0.0. This was resolved when upgrading to Node LTS 8.9.4.

See issue https://github.com/nuxt-community/create-nuxt-app/issues/39

Shouldn’t be an issue, because it’s valid code. NodeJS >= 8.3 supports spread operators natively.

Which NodeJS version do you use?

Here is what I found prior Nodejs 8.3.x the ES6 Spread Attributes is not supported and will throw this error at first, was confusing as I try installing the latest Nodejs 9.10.0 but this didn’t help.

It turns out I’m using old electron that operates with node v8.2.0 so I updated to electron@2.0.0-beta.6. and I can confirm this fixed the issue electron beta 6 is using Nodejs v8.9.3

As @qm3ster suggested add this to your main.js or script and confirm that you use Nodejs >= 8.3.x console.log(process.version)

Also ran into this issue after upgrading nuxt when running on Windows node v8.1.2. I upgraded to the latest stable node v8.10 but then ran into a can’t find NodeTemplatePlugin error. So I deleted node_modules and package-lock.json and reinstalled from scratch but then ran into:

error  in ./node_modules/vuetify/dist/vuetify.css

Module build failed: ValidationError: PostCSS Loader Invalid Options

options['useConfigFile'] is an invalid additional property

 @ ./node_modules/vuetify/dist/vuetify.css 4:14-120 13:3-17:5 14:22-128
 @ ./src/plugins/vuetify.js
 @ multi vue vue-router vue-meta vuex vue-style-loader/lib/addStylesClient css-loader/lib/css-base ~/plugins/vuetify.js

I don’t have postcss installed or configured separately or have any postcss plugins, I’m just using a vanilla Nuxt + Vuetify template. I tried downgrading nuxt@1.3.0 but that didn’t work, neither did removing global dependent packages like Webpack. In the end I had to revert to my original npm-shrinkwrap.json. Then I can update every dependency except for nuxt which always fails with the above error.

My working deps (fails when upgrading to nuxt v1.4.0):

  "dependencies": {
    "@servicestack/client": "^1.0.8",
    "@servicestack/images": "^1.0.0",
    "nuxt": "^1.3.0",
    "vuetify": "^1.0.8"
  },
  "devDependencies": {
    "@nuxtjs/proxy": "^1.1.4",
    "@servicestack/cli": "^1.0.2",
    "babel-eslint": "^8.2.2",
    "eslint": "^4.19.0",
    "eslint-friendly-formatter": "^3.0.0",
    "eslint-loader": "^2.0.0",
    "eslint-plugin-vue": "^4.3.0",
    "gulp": "^3.9.1",
    "typescript": "^2.7.2"
  }

IMO this breaking change was unnecessary, v8.1.2 was a fairly recent version and to break everyone and force them to upgrade their working node versions causes undue friction, now we’re blocked from being able to upgrade Nuxt.

Well, it’s not (completely) as stated here. Shouldn’t be an issue with a newer Node version.

same bug, project not started on the latest node

@gamelaster sounds like you need to rm -rf node_modules && npm install