Skip to content

ESM Hooks: nextResolve & nextLoad can return promises which is not reflected in documentation #49282

Description

@koshic

Affected URL(s)

https://nodejs.org/dist/latest-v20.x/docs/api/esm.html#hooks

Description of the problem

image

But in the reality nextResolve (and nextLoad) can return Promises, which is highly confusing: as an example, try...catch around 'return nextResolve(...)' will never catch the error if nextResolve returns rejected Promise. The same thing with access to nextResolve(...) result properties.

In both cases await keyword is mandatory to get predictable results.

Activity

  1. added
    docIssues and PRs related to Node.js documentation.
    on Aug 22, 2023
  2. added
    esmIssues and PRs related to the ECMAScript Modules implementation.
    on Aug 22, 2023
  3. aduh95 commented on Aug 22, 2023

    @aduh95
    Contributor

    Would you like to send a PR?

  4. koshic commented on Aug 22, 2023

    @koshic
    Author

    Would you like to send a PR?

    Sorry, I don't have enough time 😒

  5. GeoffreyBooth commented on Aug 22, 2023

    @GeoffreyBooth
    Member

    Our linter complains if we do return await, because it’s unnecessary, so you might see code like return nextResolve(...). But I think our examples always await the next* call when we’re using the returned value.

    @koshic What changes in the docs would make things more obvious to you? Would the changes discussed in #49265 (comment) have been sufficient?

  6. koshic commented on Aug 22, 2023

    @koshic
    Author

    Our linter complains if we do return await, because it’s unnecessary...

    Small off topic: do you mean https://eslint.org/docs/latest/rules/no-return-await? 'This rule was deprecated in ESLint v8.46.0 with no replacement' (c)

    @koshic What changes in the docs would make things more obvious to you? Would the changes discussed in #49265 (comment) have been sufficient?

    Looks better than existing docs due to 'async'. My issue is a bit late, thx! )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.esmIssues and PRs related to the ECMAScript Modules implementation.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions