editor.js icon indicating copy to clipboard operation
editor.js copied to clipboard

Parse error from 2.27.0 up

Open netpalantir opened this issue 2 years ago • 7 comments

Hello, I have been trying to add Editorjs to my Webpack 4 project, but unfortunately it does work only up to version 2.26.5.

As soon as I upgrade to 2.27.0 and up I get the following error (this one is obtained running @editorjs/[email protected])

ERROR in ./node_modules/@editorjs/editorjs/dist/editorjs.mjs 2922:7
Module parse failed: Unexpected token (2922:7)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|       return;
|     }
>     e ?? !this.Editor.BlockSettings.opened ? (this.Editor.Toolbar.moveAndOpen(), this.Editor.BlockSettings.open()) : this.Editor.BlockSettings.close();
|   }
|   /**

Is there some incompatibility with my toolchain? How can I help fix/debug this? Thanks.

netpalantir avatar Sep 13 '23 16:09 netpalantir

I have the same issue!

mattialerda avatar Sep 28 '23 07:09 mattialerda

I think, your babel-loader should not process node_modules. Do you have the ignore option specified in babel config? It could override the default behaviour

neSpecc avatar Sep 28 '23 07:09 neSpecc

I have the same issue!

Real-Music avatar Oct 06 '23 09:10 Real-Music

try to add this to webpack config rules: [{ test: /\.mjs$/, use: 'esbuild-loader' }],

dzantiev avatar Nov 12 '23 14:11 dzantiev

If you are using Nuxt 2:

  1. npm install esbuild-loader --save-dev
  2. Modify nuxt.config.js
build: {
    extend(config, { isDev, isClient }) {
      if (isClient) {
        config.module.rules.push({
          test: /\.mjs$/,
          include: /node_modules/,
          use: [
            {
              loader: 'esbuild-loader',
              options: {
                loader: 'jsx',  // if you're using JSX
                target: 'es2017' // set this to your desired ECMAScript version
              }
            }
          ]
        });
      }
    }
  }

phigoro avatar Nov 21 '23 20:11 phigoro

rules: [{ test: /.mjs$/, use: 'esbuild-loader' }],

Bro, where to put this line exactly

sagarsangwan avatar Jan 02 '24 10:01 sagarsangwan

If you are using Nuxt 2:

  1. npm install esbuild-loader --save-dev
  2. Modify nuxt.config.js
build: {
    extend(config, { isDev, isClient }) {
      if (isClient) {
        config.module.rules.push({
          test: /\.mjs$/,
          include: /node_modules/,
          use: [
            {
              loader: 'esbuild-loader',
              options: {
                loader: 'jsx',  // if you're using JSX
                target: 'es2017' // set this to your desired ECMAScript version
              }
            }
          ]
        });
      }
    }
  }

If after this you receive the "Element not defined" error, try importing editorJS in the mounted() lifecycle:

    mounted() {
        import('@editorjs/editorjs').then(module => {
        const EditorJS = module.default;
        this.editor = new EditorJS({
            holder: 'editor'
        });
        }).catch(err => {
            console.error('Failed to load module:', err);
        });
    }

melvinprindustry avatar Jan 08 '24 13:01 melvinprindustry