我尝试编译入口TS文件,并发生以下问题:
> tsc --project ./tsconfig.build.json
src/index.ts:2:1 - error TS1128: Declaration or statement expected.
2 export type { Icon } from './component/Button';
~~~~~~
src/index.ts:2:13 - error TS1005: ';' expected.
2 export type { Icon } from './component/Button';
~
src/index.ts:2:27 - error TS1005: ';' expected.
2 export type { Icon } from './component/Button';
~~~~~~~~~~~~~~~~~~~~
index.ts
文件的内容如下:
export { default as Button, Size, ButtonStyle, colors } from './component/Button';
export type { Icon } from './component/Button';
tsconfig.build.json
文件的内容如下:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true,
"resolveJsonModule": true,
"declaration": true,
"outDir": "./dist",
"jsx": "react",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"isolatedModules": false,
},
"include": [
"src/**/*"
]
}
对于export type {xxx}
中没有index.ts
的文件,它们已成功编译。而且,如果我从该文件中删除了export type { Icon } from './component/Button'
,该问题将消失。但是,我需要将这些对象放在另一个文件中。
有什么主意吗?
答案 0 :(得分:0)
请尝试将"module": "commonjs"
更改为"module": "esnext",
。
commonjs不支持导出/导入语法。
请在此处查看更多详细信息: https://flaviocopes.com/commonjs/