nodejs / nodejs/node

Expose `importMetaResolve(url, baseURL)` from `node:module`, and stabilize it

Open
#61,127 3 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request module
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?

In Node.js based tools it's common to need to "resolve url X as if it were imported from module Y".

Node.js does not expose this as an API, even though it implements it. It only exposes "resolve url X as if it were imported from this current module", through import.meta.resolve.

https://github.com/wooorm/import-meta-resolve is, for example, a library that is basically code copy&pasted from this repository and published on npm. The annoying part is that, as Node.js resolution rules change, libraries need to change too, and you need to basically check which version of Node.js you are on to know which rules to apply.

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

Node.js does have a solution to this: the version of import.meta.resolve that takes two arguments, gated behind a flag (--experimental-import-meta-resolve). The reason it's behind a flag is because it would be different from the import.meta.resolve implementation of browsers, that takes only one argument.

It'd be great if Node.js could expose the two-args version as an export of node:module, something like

import { resolveModuleURL } from "node:module"`;

resolveModuleURL(url, parent);

with resolveModuleURL(url, import.meta.url) being equivalent to import.meta.resolve(url).

What alternatives have you considered?

This is related to https://github.com/nodejs/node/pull/55756, which implements a more complex/comprehensive API.

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 reading Node.js's existing import.meta.resolve implementation and the behavior behind --experimental-import-meta-resolve. Compare the proposed node:module export with the more comprehensive API in pull request #55756. Done means the two-argument resolver is exposed as a stable API with behavior equivalent to the requested use case.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.