I use rollup in my typescript project for bundling. When I use "module": "commonjs"
in my tsconfig, the rollup output contains only insides of the file specified in the input
in rollup.config.js
. However, when I change tsconfig module to esnext
or es2015
everything seems to work fine. But I also use lerna
monorepo so switching to different module messes up my imports from different packages. Is there a way to do something without switching module in order for rollup to work or maybe I should rewrite some code in a project? Thanks in advance!
Here's a part of my rollup.config.js
:
import typescript from '@rollup/plugin-typescript';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
export default {
input: {
'src/index': 'src/index.ts',
'src/tests': 'src/tests.ts',
},
external: ['chalk'],
output: {
dir: 'lib',
format: 'cjs',
freeze: false,
interop: false,
sourcemap: false,
chunkFileNames: '[name].js',
},
plugins: [
nodeResolve(),
typescript(),
commonjs({include: '../../node_modules/**})
],
};
Turns out, you shouldn’t try to use “module”: “CommonJS” for bundling. If you want to keep CommonJS output just specify “format”: “cjs” in your rollup config
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With