I am trying to install editor.js into my project, however, I keep running into the error Uncaught SyntaxError: Cannot use import statement outside a module
.
I'm able to load it through there CDN but for some reason this is not able to work.
Here are the troubleshooting steps I've done so far:
- Add
"type":"module"
to JSON file - Add
type="module"
to vanilla js script - rollback version of node to v11.4.0 (this was recommended from another page through stackoverflow).
I've searched through stackoverflow and I'm not able to find a solution other then these. Any advice?
HTML File:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="editorjs"></div>
<script src="index.js"></script>
</body>
</html>
JS File:
import EditorJS from '@editorjs/editorjs';
const editor = new EditorJS();
package JSON File:
{
"name": "editor",
"version": "1.0.0",
"type": "module",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@editorjs/editorjs": "^2.18.0"
}
}
You don't need the import statement if you are getting editor.js from a CDN. In your JS file all you need is:
I fell over this myself. I think the Editor.js documentation here is misleading. It starts by saying there are 3 ways to install editor.js, but then all the remaining examples assume you've used
npm
.