[英]Export default in typescript isn´t working for commonjs
im trying to make an express application but with typescript.我正在尝试使用 typescript 进行快速申请。 With ts-node.
使用 ts 节点。
But when i try to export a function or class with export default it not works但是,当我尝试使用导出默认值导出 function 或 class 时,它不起作用
helloWorld.ts
export default () => {
console.log('Hello world!');
}
app.tss
import helloWorld from "./helloWorld.js";
helloWorld();
It returns the error: Error: Cannot find module './helloWorld.js'
它返回错误:
Error: Cannot find module './helloWorld.js'
You are importing from .js
extension ( helloWorld.js
) in your app.ts
!您正在从
app.ts
中的.js
扩展名 ( helloWorld.js
) 导入!
You should import from .ts
extension or omit the extension您应该从
.ts
扩展名导入或省略扩展名
import helloWorld from "./helloWorld.ts";
or或者
import helloWorld from "./helloWorld";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.