2

I have introduced Webpack for Django and Vue. But I get an error. I can't execute webpack. What this error?

$ node --use_strict ./node_modules/.bin/webpack --config webpack.config.js
node_modules/webpack-command/lib/cli.js:5
const { register } = require('./global');
        ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)
    at node.js:966:3
1
  • What's your node version? Does it support Object destruction? Commented Aug 7, 2018 at 8:38

3 Answers 3

2

You're trying to destructure a require call. Node version must support destructuring. Another option is to compile with babel-node.

If node supports it (node v6 and newer), check if you export register in ./global.js.

I made a demo for you here

Sign up to request clarification or add additional context in comments.

Comments

1

As I understand, you want to use your local webpack to build your app. In this case, you need to run this command:

./node_modules/webpack/bin/webpack --config webpack.config.js

Moreover, you can add the script to package json to make it shorter:

package.json

"scripts": {
    "build": "webpack --config webpack.config.js"
}

You can also use npx (https://www.npmjs.com/package/npx) to run local node_modules:

npx webpack --config webpack.config.js

Hope this helps.

Comments

0

I solved a similar issue by forcefully installing Webpack CLI. My NodeJS version is 16.

To do this, run this command:

npm install -D webpack-cli

Comments