通过脚本标记在 JavaScript 模块中导入 D3 时,Uncaught TypeError: Cannot read property 'd3' of undefined
出现错误。
读到所有主要浏览器现在都支持 JavaScript 模块后,我尝试通过<script type="module" src="network.js"></script>
此处描述的标记导入我的 D3 代码:
https://developers.google.com/web/fundamentals/primers/modules
但是,当我导入 D3 时,我收到错误消息:
d3.js:5 Uncaught TypeError: Cannot read property 'd3' of undefined
at d3.js:5
at d3.js:6
Run Code Online (Sandbox Code Playgroud)
如果我有一个index.html
文件:
d3.js:5 Uncaught TypeError: Cannot read property 'd3' of undefined
at d3.js:5
at d3.js:6
Run Code Online (Sandbox Code Playgroud)
与 D3 v5.7.0 在同一目录中,并且network.js
只包含:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<script type="module" src="network.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
要不就
import * as …
Run Code Online (Sandbox Code Playgroud)