Nuxt.js: using custom server.js have an Unexpected token 'export'

Created on 30 Aug 2020  路  5Comments  路  Source: nuxt/nuxt.js

Versions

  • nuxt: 2.14.0
  • node: 12.18.3

Reproduction

I want to benefit of full clustering node to deploy on server.


Additional Details



Steps to reproduce

What is Expected?

It should work

What is actually happening?

It makes sense that is doesn't work but if I try to change for module.exports for nuxt.config.js i have another error that i don't have for this simple reproducing project. I will come back for this part with more infos

bug-report

Most helpful comment

I decide to go with common js and module exports yeah. Now it's working thanks Daniel

I am closing the issue since I don't have the other error after switching for cjs

All 5 comments

@f3ltron Your custom server implementation isn't being processed by Nuxt and therefore will probably need to be written in JavaScript that can be run directly by node (e.g. CJS). Alternatives include using something like jiti or a transpilation step.

I decide to go with common js and module exports yeah. Now it's working thanks Daniel

I am closing the issue since I don't have the other error after switching for cjs

Hi @f3ltron. Looking at repo directly require config and new Nuxt() are not recommanded. There is new loadNuxt utility to automatically load nuxt.config and create nuxt instance for programmatic usage. It not only adds esm support, but also ensure other internal flags set properly and less risk of regressions with nuxt releases.

Ok i will test about it and close the issue if all is good

It looks it now working well with export default too. Thank's @pi0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

o-alexandrov picture o-alexandrov  路  3Comments

VincentLoy picture VincentLoy  路  3Comments

pehbehbeh picture pehbehbeh  路  3Comments

mattdharmon picture mattdharmon  路  3Comments

vadimsg picture vadimsg  路  3Comments