Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse error from 2.27.0 up #2478

Open
netpalantir opened this issue Sep 13, 2023 · 7 comments
Open

Parse error from 2.27.0 up #2478

netpalantir opened this issue Sep 13, 2023 · 7 comments

Comments

@netpalantir
Copy link

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.

@mattialerda
Copy link

I have the same issue!

@neSpecc
Copy link
Member

neSpecc commented Sep 28, 2023

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 neSpecc removed the bug label Sep 28, 2023
@Real-Music
Copy link

I have the same issue!

@dzantiev
Copy link

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

@phigoro
Copy link

phigoro commented Nov 21, 2023

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
              }
            }
          ]
        });
      }
    }
  }

@sagarsangwan
Copy link

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

Bro, where to put this line exactly

@melvinprindustry
Copy link

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);
        });
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants