https://github.com/rossma/nuxt-express
npm install
npm run dev
Client and server files are compiled and server starts up
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)
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.
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.
Most helpful comment
You can't use
ESMsyntax for yournuxt.config.jswhen calling it programmatically. Nuxt knows whatESMsyntax is but express not ofc.)Solution:
Preload the
esmmodule as in:node -r esm server/index.js