grapesjs-cli icon indicating copy to clipboard operation
grapesjs-cli copied to clipboard

Unexpected token 'export' on webpack.config.js

Open handhikadj opened this issue 1 year ago • 1 comments

Error log:

❯ npx grapesjs-cli serve


Start the development server...


/path-to-my-project/webpack.config.js:1
export default ({ config }) => {
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1288:20)
    at Module._compile (node:internal/modules/cjs/loader:1340:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at z (/path-to-my-project/node_modules/grapesjs-cli/dist/cli.js:2:3246)
    at /path-to-my-project/node_modules/grapesjs-cli/dist/cli.js:2:5256

handhikadj avatar Jan 06 '24 14:01 handhikadj

I've encountered the same problem. As i understood, CLI build uses ES5 and "export" keyword was added only in ES6, so example in README seems invalid. My solution was to do it "commonjs" way, and rewrite example with module.exports.

So example in README would look like this:

module.exports = ({ config }) => {
  return {
    ...config,
    module: {
      rules: [
        { ... },
        ...config.module.rules,
      ],
    },
  };
};

Rastuharem avatar Jul 24 '24 14:07 Rastuharem