Skip to content

Exposing the logic behind require.resolve() via a public API #16389

Closed
@zkochan

Description

@zkochan

Node.js does not expose any public API for resolving dependencies. As a result, there are many packages in the ecosystem that are trying to reimplement/mimic Node's module resolution algorithm.

resolve, resolve-from, eslint-plugin-import... just to list some of them.

The big problem with these implementations is that they don't work the way Node's require.resolve works. For instance, both resolve and resolve-from were preserving symlinks by default. I did PRs to both packages to fix this issue but they are just a drop in the ocean.

I work on pnpm - a Node package manager that uses a symlinked node_modules structure. This node_modules structure is Node.js-compatible (when Node is executed w/o the --preserve-symlinks flag) but because of the many incorrect implementations of Node's module resolution algorithm, pnpm is basically unusable with most of the popular frameworks/toolings.

Exposing Node's resolution algorithm would allow experimenting with different node_modules structures and tools/frameworks would adjust because they would resolve dependencies correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.moduleIssues and PRs related to the module subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions