I have a rollup configurations files and when I run it, it throws an exception that:
[!] SyntaxError: Unexpected token '('
at DefaultModuleLoader.moduleStrategy (node:internal/modules/esm/translators:116:18)
at DefaultModuleLoader.moduleProvider (node:internal/modules/esm/loader:203:14)
at async link (node:internal/modules/esm/module_job:67:21)
This is my rollup.config.js
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import dts from 'rollup-plugin-dts';
import packagejson from('./package.json');
export default [
{
input: "src/index.ts",
output: [
{
file: packagejson.main,
format: "cjs",
sourcemap: true,
},
{
file: packagejson.module,
format: "esm",
sourcemap: true
}
],
plugins: [
resolve(),
commonjs(),
typescript({ tsconfig: "./tsconfig.json" }),
]
},
{
input: "dist/esm/types/index.d.ts",
output: ({ file: "dist/index.d.td", format: 'esm' }),
plugin: [dts()]
}
]
and this is my package.json file code
{
"name": "react-template-component",
"version": "1.0.0",
"description": "this is a library for react",
"scripts": {
"rollup": "rollup -c"
},
"author": "Domains18",
"license": "ISC",
"type": "module",
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-typescript": "^11.1.2",
"@types/react": "^18.2.20",
"react": "^18.2.0",
"rollup-plugin-dts": "^5.3.1"
},
"dependencies": {
"rollup": "^3.28.0"
},
"main": "dist/cjs.index.js",
"module": "dist/esm/index.js",
"files":[
"dist"
],
"types": "dist/index.d.ts"
}
When I run npm run rollup -c
it should create the files specified in tsconfig and in the package and rollup.config.js