Skip to content

misleading error: Cannot find package '.../package.json', when package.json exists #49674

@isaacs

Description

@isaacs

Version

>=20.5.0

Platform

Darwin moxy.lan 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 arm64

Subsystem

modules

What steps will reproduce the bug?

mkdir -p node_modules/whatever
echo {} > node_modules/whatever/package.json
node -e 'import("whatever")'

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

Happens when a package.json exists, in a package folder that exists, but which does not define a main or '.' export.

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

The previous behavior was:

Error: Cannot find package '/Users/isaacs/dev/isaacs/resolve-import/test/fixtures/node_modules/whatever/' imported from /Users/isaacs/dev/isaacs/resolve-import/test/fixtures/[eval]

However, this is also not great, because it implies that the folder could not be found, when it clearly can be found.

What do you see instead?

Error: Cannot find package '/Users/isaacs/dev/isaacs/resolve-import/test/fixtures/node_modules/whatever/package.json' imported from /Users/isaacs/dev/isaacs/resolve-import/test/fixtures/[eval]

Additional information

The confusing bit is that it's saying it can't "find" the package.json file, which clearly does exist and is a valid package.json (albeit not one that defines a valid importable package).

A better error message would be something like:

Error: Package is not importable '/Users/isaacs/dev/isaacs/resolve-import/test/fixtures/node_modules/whatever/' imported from /Users/isaacs/dev/isaacs/resolve-import/test/fixtures/[eval]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions