nodejs / nodejs/node

Add async alternative to import.meta.resolve() with additional options

Open
#54,051 16 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request loaders
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

What is the problem this feature will solve?

Tools often need to resolve imports of files they are analyzing, which requires a resolve API that import.meta.resolve() isn't suited for.

  • The resolve() call needs a referrer path, which is only available with a flag and is non standard
  • The tool might want to specify import conditions, which are non-standard
  • The call should be async, so that file system access isn't blocking. This is especially important for online resolution in servers.

Node might be able to add non-standard options via a second argument, though I'm a bit dubious of this approach because it might preclude import.meta.resolve() from adding a standard second argument.

So currently, we have complex user land resolvers that try to emulate what Node does, like Rollup's.

What is the feature you are proposing to solve the problem?

I think node:module should provide a function to perform built-in resolution, given a referrer path and import conditions.

This API would be free from having to conform to the import.meta.resolve() standard. import.meta.resolve() would still exist for cross-platform needs of resolving from within the referrer only.

What alternatives have you considered?

No response

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.

Research direction

Start by reviewing Node's existing import.meta.resolve() behavior and the node:module API surface described in the issue. Define an asynchronous built-in resolver that accepts a referrer path and import conditions, while preserving import.meta.resolve() for standard cross-platform use; done means the proposed API and its compatibility implications are settled.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.