Babel TypeScript 预设不理解导入类型和导出类型

Dis*_*tum 9 rollup typescript babeljs

我正在尝试构建我的 npm 包,但出现此错误:

Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
Run Code Online (Sandbox Code Playgroud)

我不确定它是来自 rollup 还是 babel。

它抱怨的代码:

Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
Run Code Online (Sandbox Code Playgroud)

具体来说,它抱怨的是type。当我尝试将重新导出分离为import type和 时export type,它抱怨import type.

这是汇总插件链:

export type { Patient } from './types/entities/Patient'
Run Code Online (Sandbox Code Playgroud)

相关依赖:

[
    nodeResolve({
        extensions: ['.ts', '.tsx'],
    }),
    commonJsPlugin(),
    babel({
        babelrc: false,
        presets: [
            '@babel/preset-env',
            [
                '@babel/preset-react',
                {
                    runtime: 'automatic',
                },
            ],
            ['@babel/preset-typescript'],
        ],
        plugins: [
            [
                'babel-plugin-styled-components',
                { ssr: true },
            ],
        ],
        include: 'src/**/*',
        exclude: 'node_modules/**/*',
        babelHelpers: 'bundled',
    }),
    replacePlugin({
        values: {
            'process.env.NODE_ENV': '"production"',
        },
        preventAssignment: true,
    }),
],
Run Code Online (Sandbox Code Playgroud)

当我使用 esbuild 时一切都很好,但由于多种原因,包括缺乏对样式组件和新 JSX 转换的支持,我必须使用 Babel。