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

CJS modules with Object.defineProperty(module, 'exports', ...) broken in bundles #2364

Closed
adelespinasse opened this issue Sep 7, 2017 · 2 comments

Comments

@adelespinasse
Copy link

adelespinasse commented Sep 7, 2017

JSPM Version: 0.17.0-beta.44

Transpiler Plugin(s): babel

Details:

There are npm/CJS modules that set their exports like this:

Object.defineProperty(module, 'exports', {
  enumerable: true,
  get: getterFunction
});

An example is the ansi-styles package.

When imported, these modules normally work, but when bundled using jspm build, the value that gets imported appears to be an empty object, rather than the value returned by getterFunction.

I discovered this via the chalk package, which imports ansi-styles, but I think with chalk the bug may only manifest on Windows, so I made the following minimal reproduction:

https://github.com/adelespinasse/jspm-chalk-bug

After cloning this repo and doing npm install and jspm install, if you run jspm run jspm-chalk-bug, it will print the correct value ("Hi"). But if you run jspm build jspm-chalk-bug --node and then node build.js, it instead prints "undefined".

This worked correctly in 0.17.0-beta.41. It's broken in beta.42 through 44.

Workaround suggestions (specifically for chalk) would be appreciated too. I don't really need its functionality (it does text styling in terminal logging), but it doesn't seem to be sufficient to map ansi-styles to @empty, because the expected properties of the imported object are still undefined. But I really don't understand jspm configuration.

@aluanhaddad
Copy link
Collaborator

Thanks for raising this issue. I was able to reproduce right away thanks to the minimal repro provided.

I'm guessing this arose from a change in the SystemJS Builder as I do not see any changes in the cli itself that would lead to this.

I will investigate further.

@guybedford
Copy link
Member

Thanks, fixed in SystemJS Builder 0.16.11 and jspm 0.17.0-beta.45.

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

3 participants