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

ES module loading inconsistent with browser while handling undefined exceptions #19281

Closed
zhanzhenzhen opened this issue Mar 11, 2018 · 4 comments
Labels
esm Issues and PRs related to the ECMAScript Modules implementation.

Comments

@zhanzhenzhen
Copy link
Contributor

zhanzhenzhen commented Mar 11, 2018

  • Version: 9.8.0
  • Platform:
  • Subsystem:

If a module throws undefined, and another module imports it, it should catch undefined, like that in browser.

Browser Test

Make 2 files "index.html" and "aaa.mjs".

index.html:

<!DOCTYPE html>
<html>
<head>
<script type="module">
  "use strict";
  import('./aaa.mjs')
  .then(m => console.log("ok"))
  .catch(e => console.log("bad", e));
</script>
<title>test</title>
</head>
<body>
</body>
</html>

aaa.mjs:

"use strict";

throw undefined;

It will output "bad undefined". You can also visit my temporary page for this test: https://zzz-shadow.github.io/

Node.js Test

Make 2 files "test.mjs" and "aaa.mjs".

test.mjs:

"use strict";
import('./aaa.mjs')
.then(m => console.log("ok"))
.catch(e => console.log("bad", e));

aaa.mjs:

"use strict";

throw undefined;

When running test.mjs, it will output:

bad TypeError: Cannot read property 'stack' of undefined
    at ModuleJob.run (internal/loader/ModuleJob.js:108:9)

So, in Node, when a module throws undefined or null, the thing caught isn't the thing it throws.

Static imports are also affected.

@zhanzhenzhen
Copy link
Contributor Author

Just made a pull request. Please check.

@hiroppy hiroppy added the esm Issues and PRs related to the ECMAScript Modules implementation. label Mar 11, 2018
@benjamingr
Copy link
Member

@nodejs/modules

@benjamingr
Copy link
Member

@zhanzhenzhen thanks for opening an issue and making a PR!

@guybedford
Copy link
Contributor

This landed in #19282.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants