簡體   English   中英

未捕獲的類型錯誤:無法解析模塊說明符

[英]Uncaught TypeError: Failed to resolve module specifier

我正在嘗試將 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 有問題還是什么?

更新~

未捕獲的類型錯誤:無法解析模塊說明符“@editorjs/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');

到時候一切都會好起來的!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM