Skip to content

require.resolve() and import.meta.resolve() doesn't work with self-referenced packages #47681

@piranna

Description

@piranna

Version

v20.0.0

Platform

Linux executive 5.19.0-40-generic #41-Ubuntu SMP PREEMPT_DYNAMIC Thu Mar 23 21:39:15 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

require, import

What steps will reproduce the bug?

Call to require.resolve() created with createRequire(), or to import.meta.resolve(), passing the package name to resolve to itself.

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior? Why is that the expected behavior?

It should return the path of the package itself.

What do you see instead?

node:internal/errors:490
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@mafalda-sfu/mediasoup-cluster-cli' imported from /home/piranna/github/Mafalda/Mediasoup-cluster-CLI/node_modules/@mafalda-sfu/bytenodeify/lib/getBundlesFilenames.js
    at new NodeError (node:internal/errors:399:5)
    at packageResolve (node:internal/modules/esm/resolve:794:9)
    at moduleResolve (node:internal/modules/esm/resolve:843:20)
    at defaultResolve (node:internal/modules/esm/resolve:1070:11)
    at DefaultModuleLoader.resolve (node:internal/modules/esm/loader:306:12)
    at Object.resolve (node:internal/modules/esm/initialize_import_meta:17:25)
    at getBundlesFilenames_priv (file:///home/piranna/github/Mafalda/Mediasoup-cluster-CLI/node_modules/@mafalda-sfu/bytenodeify/lib/getBundlesFilenames.js:31:32)
    at file:///home/piranna/github/Mafalda/Mediasoup-cluster-CLI/node_modules/@mafalda-sfu/bytenodeify/lib/getBundlesFilenames.js:86:17
    at Array.map (<anonymous>)
    at default (file:///home/piranna/github/Mafalda/Mediasoup-cluster-CLI/node_modules/@mafalda-sfu/bytenodeify/lib/getBundlesFilenames.js:81:38) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Additional information

Not sure if it happens with CommonJS require() too, or just only with ESM related resolve functions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    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