我决定将我的js项目迁移到ts中,但是我面临着以下问题:ts文件中的所有导入都缺少编译的js文件中的.js扩展名。这反过来又会引发以下错误:在我的浏览器控制台上。这是代码Loading failed for the module with source “http://localhost:5500/build/test/first”.
/src/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
<script src="/build/test/last.js" type="module"></script>
</html>
/src/test/first.ts
export class First {
name: string;
constructor(name: string) {
this.name = name
}
}
/src/test/last.ts
import {First} from "./first"
class Last {
constructor() {
let name = new First("this is my name").name;
console.log(name)
}
}
new Last();
/构建/测试/第一.js
export class First {
constructor(name) {
this.name = name;
}
}
/构建/测试/最后.js
import { First } from "./first";
class Last {
constructor() {
let name = new First("this is my name").name;
console.log(name);
}
}
请注意,在最后.js,导入缺少.js扩展名,如果我手动添加缺少的扩展名,则所有内容都按预期工作。最后是我的ts配置
{
"compilerOptions": {
"target": "ESNext",
"lib": ["DOM","ES2017", "DOM.Iterable", "ScriptHost"],
"watch": true,
"rootDir": "./src",
"outDir": "./build",
"sourceMap": true,
"removeComments": true,
"noEmitOnError": true,
"strict": true,
}
}
我是否缺少一些未在导入上添加正确扩展名的内容?如果是这样,请告诉我我做错了什么。谢谢。
慕尼黑8549860
关于使用Unity3D不能进行JS脚本编写?
JS脚本怎么调用?
录不出来脚本
编写脚本直接在记事本上?
相关分类