Repository navigation
No stack trace with missing async keyword and dynamic imports #32177
Description
Activity
- addedesmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.
on Mar 10, 2020 /cc @nodejs/modules
See also #49441
Reacted by Myles Borins, Alex Yang, Jan Olaf Martin and Ben Buckschthis is a very general issue with how our error stack decoration works, and not specific to the esm loader. We can fix this in two different ways:
- Patch ModuleWrap constructor to call stack decoration util
- Move stack decoration to our prepareStackTrace handler (make all errors decorated)
Reacted by Alex Yang, Jan Olaf Martin and StarbeamrainbowlabsAh, I see @devsnek. Thanks for the explanation! I decided to report this issue because with a larger codebase it's actually a pretty significant time waster. For my PhD I have a dynamic import system for a number of subcommands that do different things in a Node.js application. It's becoming a serious challenge to figure out where I've made a mistake.....
I can grant private access to this codebase if this would help fixing the bug.
@sbrl Just want to note that adding a linter may help in this case by allowing you to locate errors and get that more useful stack trace without needing to actually execute the code.
@ExProbitasFiducia Right. I'm actually already using a linter, but it doesn't detect issues with
async/awaitfor some reason. I'm using Atom.Shouldn't really matter which editor you have, the linter should perform the same even if you execute it from the cli.
I'm a fan of eslint and they do have a rule for async/await - https://eslint.org/docs/rules/require-await
Im not sure if this is useful, or related for you but I thought it was some neat info; there is a class of bugs associated with writing an async function that never uses the await keyword. I had an issue once where the await was in a conditional and I remember that was a pretty tricky thing to track down.
require-awaitis a terrible rule; it's perfectly valid to have anasync functionwithout usingawait. The issue is usually caused by forgetting toawaita promise, which that rule won't actually help you with if you already have anawaitstatement in yourasync function.Reacted by Jan Olaf Martin, Matteo Collina, Benjamin Gruenbaum and splatterThat's the way I understand async is supposed to work. As I mentioned I've found that there are circumstances in which an async function doesn't await a value causes problem. I hope you don't run into it but that rule prevents it from happening anyway...
Again, the issue there is that you're not awaiting a promise, which is unrelated to the presence or absence of
awaitstatements in a function.github-actions commented
on Jun 27, 2026 on Jun 27, 2026 – with GitHub ActionsContributorMore actionsThis issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.- addedstaleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
on Jun 27, 2026 github-actions commented
on Jul 28, 2026 on Jul 28, 2026 – with GitHub ActionsContributorMore actionsThis issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.
What steps will reproduce the bug?
Consider the following code:
a.mjs
b.mjs
Explanation
There is obviously a bug in
b.mjsabove. Thebug()function is missing theasynckeyword`. However, when I attempt to execute the above, I get the following error:This isn't particularly helpful. Now, consider the following snippet:
c.mjs:
There's bug in this one too, but executing it yields a very different and much more helpful error:
Much better. Node gives us a helping hand by telling us where the error occurred.
How often does it reproduce? Is there a required condition?
This bug in the error message only appears to occur when a module is dynamically imported with
import("./path/to/file.mjs"). Specifically, the first error message is missing this bit:...obviously the filepath and line number would be different for b.mjs is this bit was added.
What is the expected behavior?
The first error message should look like the second.
When dynamically importing a module that is missing the async keyword on a method, the error message should tell me where the error occurred.
What do you see instead?
The bit there it tells me where the "unexpected reserved word" was found is missing. See above for examples of what's gone wrong.
Additional information
If possible, when it's the
awaitkeyword that was detected as unexpected, the error message should reflect this more closely. For example, it might be helpful to say `SyntaxError: Unexpected reserved word "await" (did you forget the "async" keyword?)" or something like that.