nuxt: SyntaxError: Unexpected token import

Version

v2.4.0

Reproduction link

https://github.com/nuxt/nuxt.js/issues/

Steps to reproduce

Fresh install of nuxt 2.4.0 Run:

npm run build

Then install pm2 Then try register the app with:

pm2 start .nuxt/server.js --watch

The app is registered and die with error on pm2 logs:

../.nuxt/server.js:1
(function (exports, require, module, __filename, __dirname) { import { stringify } from 'querystring' 

SyntaxError: Unexpected token import
  at createScript (vm.js:80:10)
  at Object.runInThisContext (vm.js:139:10)
  at Module._compile (module.js:617:28)
  at Object.Module._extensions..js (module.js:664:10)
  at Module.load (module.js:566:32)
  at tryModuleLoad (module.js:506:12)
  at Function.Module._load (module.js:498:3)
  at Function._load (/usr/lib/node_modules/pm2/node_modules/@pm2/io/build/main/metrics/httpMetrics.js:172:43)
  at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:27:21)
  at Module._compile (module.js:653:30)

Same error about token issue occours if I try use Passenger.

What is expected ?

Load in both Passenger and PM2 without errors (on this issue, fixing the token error about import { stringify })

What is actually happening?

Can not run because the error on token importing { stringify }

Additional comments?

Vanilla Vue run on both: Passenger and PM2 without errors.

<div align="right">This bug report is available on Nuxt community (#c8928)</div>

About this issue

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

Most upvoted comments

@Anaphase https://discord.nuxtjs.org/ is better place to ask such questions.

https://discord.nuxtjs.org/

not good at all, because now a person like me trying to find a solution for this bug and i am expecting to find it here.

Remove node_modules, remove yarn.lock/package-lock.json and reinstall.

I’m not sure if I’m in the right place here, but I’ve been trying to get babel to transpile es6 imports within server/index.js and I can’t seem to figure out how to get that to work… I’ve tried changing the npm run dev command to have nodemon run server/index.js with babel-node, but since the project has no .babelrc I have to define one for babel-node to read.

Should I just have nuxt read from the .babelrc with something like nuxt-babel? Or am I missing something obvious here? Is it possible to have babel transpile es6 imports statements on server-side scripts? This is my first few hours with Nuxt so I’m sorry if this is a stupid question.

@manniL I deleted it. Thank you for the info.

After I deleted the babel block from nuxt.config.js everything worked fine.

I also deleted

from package.json

Updated version of my code. Now working: https://codesandbox.io/s/7m6v78m3v0

@manniL Yes, but I was referring specificially to comments that mentioned running .nuxt/server.js directly which means they are not running nuxt programatically.

@jloewe that preset is used by default and AFAIK y<ou don’t need the plugin as well so you can try deleting the whole block ☺️