Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to bundle require statements from esm? #5462

Open
tornadocontrib opened this issue Apr 8, 2024 · 3 comments
Open

How to bundle require statements from esm? #5462

tornadocontrib opened this issue Apr 8, 2024 · 3 comments

Comments

@tornadocontrib
Copy link

Hello,

I would like to know how to make the rollup bundle packages imported by require statement from esm.

For example,

// test.mjs
import test from 'test'
const some_module = require('some');

would leave

// output.js
const some_module = require('some');

like this so the package imported by require statement isn't bundled

How should I force it to bundle?

Thanks,

@liuly0322
Copy link
Contributor

You need @rollup/plugin-commonjs. If you want to use both include and require statement in the same file, set transformMixedEsModules to true. Example rollup config file:

import commonjs from '@rollup/plugin-commonjs';

export default {
  input: 'index.js',
  output: {
    dir: 'output',
    format: 'cjs'
  },
  plugins: [commonjs({
    transformMixedEsModules: true
  })]
};

@tornadocontrib
Copy link
Author

@liuly0322 Have tried but still it wouldn't bundle modules imported by require statement

@liuly0322
Copy link
Contributor

@liuly0322 Have tried but still it wouldn't bundle modules imported by require statement

Check the config file usage, are you using -c option (for example npx rollup -c or add -c option in your package.json scripts)? If that doesn't work, would you please provide a minimal reproducible example repo and the command you use to bundle?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants