未定义 TypeScript 导出 [英] TypeScript exports is not defined
本文介绍了未定义 TypeScript 导出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用导出和导入,但它不起作用我收到一个错误
I'm trying to use export and import but it not working I get an error
这是我的 HTML 代码:
Here is my code HTML :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
@RenderBody()
<script src="~/scripts/user.js"></script>
<script src="~/scripts/main.js"></script>
</body>
</html>
用户.ts:
export class User {
firstName: string;
lastName: string;
}
main.ts
import { User } from "./user";
这里也是异常截图:
推荐答案
您有几个选择:
选项 1: 使用像 Webpack 这样的模块加载器,浏览器等
Option 1: Use a module loader like Webpack, Browserify, etc.
选项 2: 如果您只想将 *.ts
编译为 *.js
而没有任何模块导入或导出,请设置 compilerOptions.module
在 tsconfig.json
中设置为none".请注意,当您将 compilerOptions.module
设置为none"时,您将无法导出/导入模块.
Option 2: If you just want to compile *.ts
to *.js
without any module imports or exports, set compilerOptions.module
to "none" in your tsconfig.json
. Note that you won't be able to export/import modules when you set compilerOptions.module
to "none".
这篇关于未定义 TypeScript 导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文