Skip to content

Can't self-reference a scoped package using its name #37618

@piranna

Description

@piranna

Not sure if it's a Node.js or jest-resolve issue, so I'm cross-posting it.

What steps will reproduce the bug?

At Node.js packages docs it says it's possible to self-reference and import a package from it's own modules by using the package name, the same was as it's done with dependencies installed on node_modules. I'm self-referencing my package itself in my jest tests, it says it can't find it:

   Test suite failed to run

    Cannot find module '@piranna/rpc' from '__tests__/index.js'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:306:11)

Since my package has a scope (package name is in the form with @<scope>/<packageName>) and there's no examples or references in Node.js docs about self-referencing scoped packages, maybe this is a Node.js packages resolving algorythm.

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

It happens me always. Maybe related to jest-resolve package.

What is the expected behavior?

The self-referenced package should be imported.

What do you see instead?

It give an error stating it can't find the module.

Additional information

I'm trying to do it that way in combination with package.json imports and Jest projects and testEnvironment, I can be able to test my code in multiple environments doing different imports for each one, so I can apply polyfills automatically.

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