【发布时间】:2021-10-03 09:10:31
【问题描述】:
我试图在本地类型脚本项目中使用库 bpmn.io 来扩展它。
所以我尝试使用语句import {BpmnModeler, BpmnViewer} from 'bpmn-js' 导入其组件。该库显然在内部使用 es6 模块来导入和导出内容。
当我尝试使用 ts-node <path/to/my/index.ts>(我的 typescript 项目的入口点)运行此代码时,我在终端中从 bpmn.io 库的默认导出处获得了一个意外的令牌“导出”。
下面是我的 tsconfig.json
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"lib": [
"es2020"
],
"allowJs": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./dist",
"composite": true,
"strict": true,
"moduleResolution": "node",
"rootDirs": [
"."
],
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"references": [],
"watchOptions": {
"fallbackPolling": "dynamicPriority",
"excludeDirectories": [
"**/node_modules",
"build"
]
}
}
我相信这是因为我在上面的 tsconfig.json 中设置了 module: "commonjs" 选项。但是,如果我将其更改为 module: "es6",那么我必须在我的 package.json 中设置 type="module" 选项,这会导致 unknonwn 文件扩展名 .ts 错误。这里有点问题
【问题讨论】:
-
"unknonwn 文件扩展名 .ts" - 但是您的 package.json 应该引用已编译的 .js 文件,而不是 typescript 源?
-
当我使用节点时,当然。不过我正在使用 ts-node。
标签: typescript ecmascript-6 es6-modules ts-node