typescript - 打字稿导入/导出给出“SyntaxError: Unexpected token 'export'”
问题描述
我有一个使用打字稿的 asp.net 核心项目。我正在使用这样的导入/导出语法:
import ConfigurationDocument from "./Configuration Document";
import ServiceEndpoint from "./Service - Endpoints";
export default class ConfigurationDocumentManager
该项目构建良好,但是当我尝试导航到使用这样链接的 ts 的页面时:
<script src="/js/Manager - Configuration Document.js" type="module"></script>
我收到错误:
SyntaxError: Cannot use import statement outside a module
SyntaxError: Unexpected token 'export'
文件命名约定是我工作场所的标准,所以我不知道这是否是问题所在。如果我将所有 ts 文件放在 wwwroot 中,删除 tsconfig 并删除所有导入/导出,项目构建并运行良好,所以我认为这不是问题。
我的 tsconfig 如下:
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "ES2020",
"lib": [ "ES2020", "DOM" ],
"outDir": "wwwroot/js/",
"module": "ES2020"
},
"exclude": [
"node_modules",
"wwwroot"
]
}
我确信这很明显,但我已经用谷歌搜索了好几天,并尝试了数十种解决方案,但没有任何效果。如果有人可以向我展示一个可以工作的 tsconfig 文件,那就太好了。
我的项目是这样的:
>root
>wwwroot
>TypeScript
(c# files etc)
解决方案
推荐阅读
- python - 在 AbstractBaseUser Django 中使用电话号码字段
- python - 如何在 dagster 中并行运行任务?
- asp.net - 如何确定 IIS 无法读取 web.config 的原因?
- r - R Studio 无响应
- node.js - 邮递员不发送嵌套的 JSON 数据
- javascript - 将 JSON 解析为数组中的字符串并创建嵌套对象
- raspberry-pi - 设置您的 Raspberry Pi 环境以制作 Alexa 时出现 Raspberry pi 3 错误
- python - Pandas Dataframe:如何使用 NaN 管理列的自动浮点转换
- javascript - 如何遍历 JSON 并向对象添加值
- xtermjs - 如何在 xterm.js 中使用滚动线