【问题标题】:Uncaught TypeError: Failed to resolve module specifier未捕获的类型错误:无法解析模块说明符
【发布时间】:2021-05-19 06:05:14
【问题描述】:

我正在尝试将 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 有问题还是什么?

【问题讨论】:

  • 能否请您从问题中删除您对 JS 的看法
  • 由于您想直接在 html 中包含 JS,您可以使用 CDN &lt;script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"&gt;&lt;/script&gt; 而不是直接使用节点模块来处理 html 变得困难,这需要捆绑器、解析器、babel 等等跨度>
  • 我对NodeJS一无所知,在他们的“入门”中,他们提供了三种安装方式,composer,CDN和Manual,我选择了第三种,他们说要下载js和用这种方式,我的错在哪里?
  • @Andreas 我删除了我对 JS 的看法 ;-)

标签: javascript


【解决方案1】:

使用&lt;script src='lib/editor.js'&gt;&lt;/script&gt;时不要使用导入

之前

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

之后

    const editor = new EditorJS('editorjs');

一切都会好起来的!

【讨论】:

    猜你喜欢
    • 2020-05-18
    • 2022-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-11
    • 2020-01-17
    • 2021-09-10
    • 2022-10-25
    相关资源
    最近更新 更多