TypeError:解决模块说明符时出错 [英] TypeError: Error resolving module specifier

查看:693
本文介绍了TypeError:解决模块说明符时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到 TypeError:尝试导入d3.js库时,解析模块说明符:d3 出错。该项目使用npm,并且在Firefox中遇到了错误。

I am getting TypeError: Error resolving module specifier: d3 when trying to import d3.js library. The project uses npm and the error has been encountered in Firefox.

index.html

<!DOCTYPE html>
<html lang="en">
  <header>
    <meta charset="utf-8" />
    <title>D3</title>
  </header>

  <body>
    <div id="svg"></div>
    <script src="./index.js" type="module"></script>
  </body>
</html>

index.js

import * as d3 from "d3";


推荐答案

像 d3这样的裸导入符仍然不受支持在浏览器中。导入说明符应为文件的绝对路径或相对路径。例如, import * as d3 from ./d3.js;

Bare import specifiers like "d3" are still not supported in browsers. Import specifiers should be either an absolute or a relative path to the file. For example, import * as d3 from "./d3.js";

相对路径说明符应以 / ./ ../

Relative path specifiers should start with /, ./, or ../.

这篇关于TypeError:解决模块说明符时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆