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

fix(npm): remove export binding to match node #15837

Merged
merged 2 commits into from
Sep 10, 2022

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Sep 9, 2022

Closes #15790


// This will throw because it's lost its context.
// (same thing occurs with Node's cjs -> esm translation)
getValue();
Copy link
Member Author

@dsherret dsherret Sep 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example in Node:

> cat other.cjs
module.exports = {
  test() {
    return this.other();
  },
  other() {
    return 5;
  }
};

> cat file.mjs
import defaultImport from "./other.cjs";
import * as namespaceImport from "./other.cjs";
import { test } from "./other.cjs";

console.log(defaultImport.test());
console.log(test());
console.log(namespaceImport.test()); // this also throws in Node, but actually not currently in this PR in Deno...

> node file.mjs
5
V:\scratch-npm\other.cjs:3
    return this.other();
                ^

TypeError: this.other is not a function
    at Module.test (V:\scratch-npm\other.cjs:3:17)
    at file:https:///V:/scratch-npm/file.mjs:6:12
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)

Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dsherret dsherret merged commit 3b0de03 into denoland:main Sep 10, 2022
@dsherret dsherret deleted the fix_npm_remove_binding branch September 10, 2022 15:38
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

Successfully merging this pull request may close these issues.

npm classes lose their prototypes
2 participants