Skip to content

Commit

Permalink
module: document ES modules without file extension within module scope
Browse files Browse the repository at this point in the history
  • Loading branch information
LiviaMedeiros committed Sep 7, 2023
1 parent fcb8be9 commit bfaedc4
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<!-- YAML
added: v8.5.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/49531
description: ES modules within `module` package can be extensionless.
- version: v20.0.0
pr-url: https://github.com/nodejs/node/pull/44710
description: Module customization hooks are executed off the main thread.
Expand Down Expand Up @@ -156,15 +159,6 @@ via the paths defined in [`"exports"`][].
For details on these package resolution rules that apply to bare specifiers in
the Node.js module resolution, see the [packages documentation](packages.md).

### Mandatory file extensions

A file extension must be provided when using the `import` keyword to resolve
relative or absolute specifiers. Directory indexes (e.g. `'./startup/index.js'`)
must also be fully specified.

This behavior matches how `import` behaves in browser environments, assuming a
typically configured server.

### URLs

ES modules are resolved and cached as URLs. This means that special characters
Expand Down Expand Up @@ -1008,7 +1002,7 @@ _isImports_, _conditions_)
> 5. Let _packageURL_ be the result of **LOOKUP\_PACKAGE\_SCOPE**(_url_).
> 6. Let _pjson_ be the result of **READ\_PACKAGE\_JSON**(_packageURL_).
> 7. If _pjson?.type_ exists and is _"module"_, then
> 1. If _url_ ends in _".js"_, then
> 1. If _url_ ends in _".js"_ or lacks file extension, then
> 1. Return _"module"_.
> 2. Return **undefined**.
> 8. Otherwise,
Expand Down

0 comments on commit bfaedc4

Please sign in to comment.