Nuxt.js: nuxt.config.js unexpected identifier import webpack nodemon

Created on 13 Mar 2019  路  2Comments  路  Source: nuxt/nuxt.js

Version

v2.4.5

Reproduction link

https://github.com/rossma/nuxt-express

Steps to reproduce

npm install
npm run dev

What is expected ?

Client and server files are compiled and server starts up

What is actually happening?

The following exception is thrown

(function (exports, require, module, __filename, __dirname) { import webpack from 'webpack'
^^^^^^^

SyntaxError: Unexpected identifier
at new Script (vm.js:80:7)
at createScript (vm.js:274:10)
at Object.runInThisContext (vm.js:326:10)
at Module._compile (internal/modules/cjs/loader.js:664:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)

Additional comments?

Create a nuxt app using npx create-nuxt app
Specify express as an option
Following script is generated in the package,json
"dev": "cross-env NODE_ENV=development nodemon server/index.js --watch server",

Modify the nuxt.config.js file so that we import webpack : import webpack from 'webpack'

call npm run dev and exception occurs.

running with nuxt command doesn't cause this exception.

instead of using import I still with using require.

This bug report is available on Nuxt community (#c8825)
bug-report

Most helpful comment

You can't use ESM syntax for your nuxt.config.js when calling it programmatically. Nuxt knows what ESM syntax is but express not ofc.)

Solution:

Preload the esm module as in:
node -r esm server/index.js

All 2 comments

You can't use ESM syntax for your nuxt.config.js when calling it programmatically. Nuxt knows what ESM syntax is but express not ofc.)

Solution:

Preload the esm module as in:
node -r esm server/index.js

The docs do show to 'import webpack' here https://nuxtjs.org/faq/webpack-plugins/

So it either works somehow, or if someone could update the docs here, that would be great.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vadimsg picture vadimsg  路  3Comments

shyamchandranmec picture shyamchandranmec  路  3Comments

vadimsg picture vadimsg  路  3Comments

bimohxh picture bimohxh  路  3Comments

vadimsg picture vadimsg  路  3Comments