【发布时间】:2021-11-20 19:41:17
【问题描述】:
我正在尝试通过 Typescript 在网页上使用Litepicker,但发出的 JS 无法加载模块。这就是我所拥有的:
index.html
<html>
<body>
<input type="text" id="picker">
</body>
<script type="module" src="node_modules/litepicker/dist/litepicker.js"></script>
<script type="module" src="test.js"></script>
</html>
test.ts
import Litepicker from './node_modules/litepicker/dist/types/index';
new Litepicker({
element: document.getElementById('picker'),
});
test.ts 编译良好,发出的 test.js 与 test.ts 文件相同。
但是,当我在浏览器上加载 index.html 时,出现以下错误:
GET https://192.168.0.160/test/node_modules/litepicker/dist/types/index net::ERR_ABORTED 404(未找到)test.js:1
如果我像这样从 test.ts 中删除导入:
declare let Litepicker: any;
new Litepicker({
element: document.getElementById('picker'),
});
然后emmited JS在浏览器上运行良好,我没有收到任何错误。
那么,如何在 .ts 上导入模块并且在 .js 上没有错误?
(这是我的 tsconfig.json 文件)
{
"compilerOptions": {
"target": "es2020",
"sourceMap": false,
}
}
【问题讨论】:
标签: typescript import