How can I install the Editor.js module in my Glitch project?

0

I’m trying to install Editor.js using node.js package in my hello-express Glitch project. This is the package via NPM:

npm i @editorjs/editorjs --save

I included the module in my javascript file as mentioned in the Editor.js documentation:

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

But the following error appears in the browser console:

Uncaught SyntaxError: Cannot use import statement outside a module

I’m sure it’s a bad installation in my Glitch project but I don’t know how to fix it. Could you help me?

That isn’t a installation issue. import statements can only be used in modules. Try this instead:

<script type="module">
import EditorJS from '@editorjs/editorjs';
const editor = new EditorJS();
</script>

This turns it into a module.

Wow, I had no idea about the type attr. Are there docs on this?

1 Like

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-type

<script type="script"> would make for a bad attribute value ngl

Modules in client side - this is getting interesting :thinking:

Yeah like monaco editor where you have to link to the modules in node_modules folder

1 Like