镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

esm modules documentation doesn't describe how to implement a module #28060

Description

@sam-github

I read https://nodejs.org/api/esm.html and found that while it had good/exhaustive coverage of import, it doesn't describe how to export a module. Unless I very much missed it, there is not even a single example of a ESM module.

I know, import and export are part of the language base, and node's documentation doesn't cover the Javascript language. In this case, I think its necessary to at least have a single example, such as:

export function whatever() {};
export function somethingElse() {};
export default {
  whatever,
   somethingElse,
};

Not having this makes the import docs hard to understand, they talk a lot about "exports" and "default exports", but without defining them.

Also, having read through ~600 lines of documentation on ECMAscript modules and still having to scrape the internet to figure out how to write one is not a great documentation experience :-).

  • Version: master/12
  • Platform: any
  • Subsystem: doc

Activity

  1. added
    docIssues and PRs related to Node.js documentation.
    esmIssues and PRs related to the ECMAScript Modules implementation.
    on Jun 4, 2019
  2. sam-github commented on Jun 4, 2019

    @sam-github
    ContributorAuthor

    /to @nodejs/modules-active-members

  3. karthikPullela commented on Jun 18, 2019

    @karthikPullela

    I'm new to contributing to Node.js but I can try to take point on this.

  4. GeoffreyBooth commented on Nov 22, 2019

    @GeoffreyBooth
    Member

    The section https://nodejs.org/api/esm.html#esm_writing_dual_packages_while_avoiding_or_minimizing_hazards includes some example ES modules with exports.

    Admittedly that’s not the export equivalent of https://nodejs.org/api/esm.html#esm_code_import_code_specifiers, but as the OP notes, it’s not Node’s job to document the JavaScript language itself. There’s nothing about export that Node does differently than the spec, or that’s special in Node as compared to any other runtimes. https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export should be sufficient I would think.

  5. added a commit that references this issue on Jul 27, 2026
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