2

I'm trying to integrate editorjs (https://editorjs.io/) in my project then I downloaded the editor.js to my project and loaded it in my html page:

    <script src='lib/editor.js'></script>

And I added:

    <script src='lib/myeditorloader.js'></script>

Which contains:

    import EditorJS from '@editorjs/editorjs';
    const editor = new EditorJS('editorjs');

I got that error:

Uncaught SyntaxError: Cannot use import statement outside a module

I added type='module' to get and as thing are never simple with js, I got this error:

Uncaught TypeError: Failed to resolve module specifier "@editorjs/editorjs". 
Relative references must start with either "/", "./", or "../".

I tried import EditorJS from './editor.js'; but now I get:

Uncaught SyntaxError: The requested module './editor.js' does not provide an export named 'default'

Is editojs buggy or what ?

4
  • 1
    Can you please remove your opinion about JS from the question Commented Feb 16, 2021 at 11:33
  • As you want to include the JS in your html directly you can use CDN <script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script> instead of making it difficult using node modules for html directly which will require bundler, parser, babel, lot more Commented Feb 16, 2021 at 11:33
  • I don't know anything about NodeJS, in their "getting started", they give 3 way to install, composer, CDN and Manual, I chose the third, and they say to download the js and use that way, where's my mistake ? Commented Feb 16, 2021 at 12:39
  • @Andreas I removed my opinion about JS ;-) Commented Feb 16, 2021 at 12:42

1 Answer 1

1

Update~

Uncaught TypeError: Failed to resolve module specifier "@editorjs/editorjs". Relative references must start with either "/", "./", or "../".

First, install editorjs using command

 npm i @editorjs/editorjs --save

Then import it like

 import EditorJS from '@editorjs/editorjs'

Original Answer~

Don't use import while using <script src='lib/editor.js'></script>

Before

    import EditorJS from '@editorjs/editorjs';
    const editor = new EditorJS('editorjs');

After

    const editor = new EditorJS('editorjs');

Everything will be fine then!

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

1 Comment

Hello, I had the same issue and with your answer worked great! But how I would add the tools? If I state that I want to add a Header, it will return an error: Uncaught ReferenceError: Header is not defined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.