我试图在我的项目中集成editorjs (https://editorjs.io/)然后我下载了editor.js到我的项目并将其加载到我的html页面:
<script src='lib/editor.js'></script>
我还加了:
<script src='lib/myeditorloader.js'></script>
包含:
import EditorJS from '@editorjs/editorjs';
const editor = new EditorJS('editorjs');
我得到了那个错误:
Uncaught SyntaxError: Cannot use import statement outside a module
我添加了type='module'
来获得,因为事情从来没有简单的js,我得到了这个错误:
Uncaught TypeError: Failed to resolve module specifier "@editorjs/editorjs".
Relative references must start with either "/", "./", or "../".
我试过import EditorJS from './editor.js';
,但现在我得到:
Uncaught SyntaxError: The requested module './editor.js' does not provide an export named 'default'
editojs有bug吗?
更新~
首先,使用命令 安装editorjsUncaught TypeError: Failed to resolve module specifier "@editorjs/editorjs"相对引用必须以"/"、"/"或"…/"开头。
npm i @editorjs/editorjs --save
然后导入
import EditorJS from '@editorjs/editorjs'
原始答案~
使用<script src='lib/editor.js'></script>
时不要使用import
import EditorJS from '@editorjs/editorjs';
const editor = new EditorJS('editorjs');
后const editor = new EditorJS('editorjs');
一切都会好起来的!