Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rollupjs doesn't bundle all files

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/**})
  ],
};

like image 841
LionKing Avatar asked Oct 14 '25 19:10

LionKing


1 Answers

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

like image 197
LionKing Avatar answered Oct 17 '25 11:10

LionKing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!