Babel TypeScript preset doesn't understand import type and export type

Viewed 420

I'm trying to build my npm package, but getting this error:

Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)

I'm not sure if it's coming from rollup or babel.

The code it's complaining about:

export type { Patient } from './types/entities/Patient'

Specifically, it's complaining about type. When I tried separating the re-export into import type and export type, it complained about import type.

Here's the chain of rollup plugins:

[
    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,
    }),
],

Relevant dependencies:

{
  "@babel/core": "^7.14.6",
  "@babel/preset-env": "^7.14.7",
  "@babel/preset-react": "^7.14.5",
  "@babel/preset-typescript": "^7.14.5",
  "@rollup/plugin-babel": "^5.3.0",
  "@rollup/plugin-commonjs": "^19.0.0",
  "@rollup/plugin-node-resolve": "^13.0.0",
  "@rollup/plugin-replace": "^2.4.2",
  "babel-plugin-styled-components": "^1.12.0",
  "rollup": "^2.52.2",
  "typescript": "^4.3.4"
}

It was fine when I was using esbuild, but for a number of reasons, including lack of support for styled components and the new JSX transform, I have to use Babel.

0 Answers
Related