【发布时间】:2021-08-07 05:53:05
【问题描述】:
我正在尝试使用 Typed.js 库并使用 NPM 安装它。我在“main.js”文件中使用了一个简单的示例,并将其与<script src="./main.js"></script> 链接。错误一直显示Error: Cannot using import outside a module"。所以我使用了<script type="module" src="./main.js"></script>。但现在显示Failed to resolve module specifier......Relative path references must start with "/", "./", "../"
我从Typed.js官方文档中复制了代码。
// Can also be included with a regular script tag
import Typed from 'typed.js';
var options = {
strings: ['<i>First</i> sentence.', '& a second sentence.'],
typeSpeed: 40
};
var typed = new Typed('.element', options);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1 class="element"></h1>
<script src="./main.js"></script>
</body>
</html>
【问题讨论】:
-
你能在这里分享你的
main.js吗?
标签: javascript node.js npm