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

Non-enumerable properties and __esModule are inconsistently imported #11995

Closed
evanw opened this issue Nov 15, 2020 · 0 comments · Fixed by #12002
Closed

Non-enumerable properties and __esModule are inconsistently imported #11995

evanw opened this issue Nov 15, 2020 · 0 comments · Fixed by #12002

Comments

@evanw
Copy link

evanw commented Nov 15, 2020

Bug report

What is the current behavior?

If you import a CommonJS module from an ES6 module, non-enumerable properties are sometimes imported and sometimes not imported depending on the import syntax used. This situation comes up when a CommonJS module does module.exports = class { static property() {} }. In that case property is non-enumerable.

If the current behavior is a bug, please provide the steps to reproduce.

Repro: https://repl.it/@EvanWallace1/webpack-commonjs-import-inconsistency

// import.mjs
import * as test from './test/index.js'

console.log('nonEnumerable (direct):', test.nonEnumerable)
console.log('nonEnumerable (indirect):', test[Math.random() < 2 && 'nonEnumerable'])

console.log('__esModule (direct):', test.__esModule)
console.log('__esModule (indirect):', test[Math.random() < 2 && '__esModule'])
// test/index.js
Object.defineProperty(exports, 'nonEnumerable', {value: true})

Note that the code above uses test[Math.random() < 2 && 'property'] to represent a dynamic property access. It's not the intention of this issue to special-case that syntax to behave like test.property.

What is the expected behavior?

Expected:

Either this:

nonEnumerable (direct): true
nonEnumerable (indirect): true
__esModule (direct): true
__esModule (indirect): true

Or this:

nonEnumerable (direct): true
nonEnumerable (indirect): true
__esModule (direct): undefined
__esModule (indirect): undefined

Observed:

nonEnumerable (direct): true
nonEnumerable (indirect): undefined
__esModule (direct): undefined
__esModule (indirect): true

Other relevant information:
webpack version: 5.4.0
Node.js version: v12.18.3
Operating System: linux
Additional tools:

I'm working on improving esbuild's compatibility with other bundlers. This inconsistency tripped me up in the past when trying to figure out what forms of importing Webpack supports. Ideally it would be consistent. I'm guessing no one else has pointed this out yet so I figured I should log an issue. Here's the context: evanw/esbuild#532 (comment).

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

Successfully merging a pull request may close this issue.

3 participants