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

commonJS module's this should be window in browser #3324

Closed
vjpr opened this issue Jun 15, 2023 · 1 comment
Closed

commonJS module's this should be window in browser #3324

vjpr opened this issue Jun 15, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@vjpr
Copy link
Contributor

vjpr commented Jun 15, 2023

What version of Bun is running?

0.6.10

What platform is your computer?

macos

What steps can reproduce the bug?

Try use source-map library in a bundle.

isBrowserEnvironment check fails.

Transpiled code:

var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);

...

var require_read_wasm = __commonJS((exports, module) => {
  var __dirname = "/Users/Vaughan/dev-mono/thirtyfive/node_modules/.pnpm/source-map@0.7.4/node_modules/source-map/lib";
  var isBrowserEnvironment = function() {
    return typeof window !== "undefined" && this === window;
  }.call();
  if (isBrowserEnvironment) {

this === window fails...this is undefined.

What is the expected behavior?

this should be window.

What do you see instead?

It's undefined.

Additional information

The use of () => {} instead of function probably causes this as it removes the this binding.

@vjpr vjpr added the bug Something isn't working label Jun 15, 2023
@vjpr
Copy link
Contributor Author

vjpr commented Jun 15, 2023

Nevermind, was an issue in original package.

mozilla/source-map#459

@vjpr vjpr closed this as completed Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant