I've encountered a problem while working with Rollup 4:
[!] RollupError: Expected ',', got ':' (Note that you need plugins to import files that are not JavaScript) src/index.ts (48:19)
Although my Babel configuration appears to be functioning correctly, when I directly run Babel, it transpiles the code without any issues:
npx babel src/index.ts // Executes successfully
This is my babel.config.json
:
{
"presets": [
[
"@babel/preset-env",
{
"targets": "defaults"
}
],
"@babel/preset-typescript"
]
}
Now moving on to my rollup.config.mjs
. Initially, I suspected an issue with loading my external babel.config.json
, so I decided to replicate the Babel configuration inside the babel()
plugin:
import babel from '@rollup/plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
export default {
input: 'src/index.ts',
output: {
file: 'dist/index.esm.js',
format: 'esm',
},
plugins: [
resolve(),
babel({
babelrc: false,
presets: [
[
'@babel/preset-env',
{
targets: 'defaults',
},
],
'@babel/preset-typescript',
],
}),
],
};
Despite this modification, the error persists. Below is my tsconfig.json
:
{
"compilerOptions": {
"target": "ESNext",
"declaration": true,
"declarationDir": "dist/",
"isolatedModules": true,
"moduleResolution": "bundler",
"lib": ["esnext", "DOM"]
}
}