doc: Error for "." and ".." specifiers differs from documented Resolver Algorithm

Open Beginner friendly
#39,873 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Quiet
Tech stack
javascript, node.js

Research direction

Start with the ESM Resolver Algorithm specification at the linked esm.html section and compare step 3 with the observed import behavior for "." and "..". Confirm whether the documented algorithm or the runtime behavior is intended, then update the documentation so the algorithm and reported error agree; the issue is done when the documented result matches Node's behavior.

Written by the indexing model from the issue text.

Description

doc esm
  • Version: ✍️

16.7.0

  • Platform: ✍️

Linux penguin 5.4.119-14945-gafc97d54f809 #1 SMP PREEMPT Tue Aug 10 21:49:04 PDT 2021 x86_64 GNU/Linux

  • Subsystem: ✍️

module

Location

Affected URL(s):

Description

I'm not sure if this is a bug with the ESM resolver or with the docs but basically if we do:

import foo from ".";

Then Node throws a ERR_UNSUPPORTED_DIR_IMPORT error, based on a reading of the Resolver Algorithm I expected this to be ERR_INVALID_MODULE_SPECIFIER.

As CommonJS already treats require(".") and require("..") as directory imports the current behaviour in Node is probably the best, so the docs should be updated to reflect it. This would involve changing ESM_RESOLVE step 3 to:

  • Otherwise, if specifier starts with "/", "./" or "../", or specifier equals "." or ".." then

Although if the current documented behaviour is the intended behaviour then the error needs updating.

Dominant language
JavaScript
Stars
122k
Forks
37.4k
Avg merge
4d 3h
Merged PRs (30d)
273

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nodejs/node

All issues in nodejs/node

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.