plugins: [commonjs] cross import between entry commonjs modules is broken

  • Rollup Plugin Name: @rollup/plugin-commonjs
  • Rollup Plugin Version: Latest
  • Rollup Version: Latest
  • Operating System (or Browser): MacOS, Repl.it
  • Node Version: v12.16.3

How Do We Reproduce?

https://repl.it/@csr632/rollup-plugin-repro

Expected Behavior

checkout dist/test1.js , it access test2 module as test2.__moduleExports, which is clearly undefined.

Actual Behavior

dist/test1.js should log test2 correctly

Output format is esm, so maybe related to https://github.com/rollup/plugins/issues/400. But in my case, I have multi entry modules.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 19 (19 by maintainers)

Commits related to this issue

Most upvoted comments

@lukastaegert Ok so just in case I forget later - it’s basically a shortcut to the stuff that’s stuffed onto module.exports.foo = bar (vs. module.exports = ...), for other internal modules (in the same rollup) to use, to avoid the unwrapExports(...) from pulling a member named default in case it exists. It basically allows to workaround all the babel __esModule/default hacks internally, so it refers to the right objects.

Also most of its references gets shaken off by rollup and replaced with default import when relevant and possible. That’s why it’s hard to see the source of the problem in the REPL.

My other PR from today actually has a test that fails when I remove the whole __moduleExports thing, and that is what clarified things to me. Pure luck.

I can confirm this is resolved by #501.

I started #481 to move all interop issues including this one forward.