Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Loaded ESM module can't refer to mapped imports from package.json:{imports...} #13251

Closed
danfuzz opened this issue Sep 12, 2022 · 3 comments

Comments

@danfuzz
Copy link

danfuzz commented Sep 12, 2022

Version

29.0.3

Steps to reproduce

  1. Clone the gist https://gist.github.com/danfuzz/42911f598060bc255c1421ca27a616cf.
  2. Run the script do-test from the gist. (It will install Jest locally, create a src directory that has the structure that I found to be problematic, and then run Jest on the test in that directory.)

Expected behavior

I expected to see the test run.

Actual behavior

The following output:

 FAIL  tests/Thing.test.js
  ● Test suite failed to run

    Cannot find module '#x/Thing' from 'index.js'

      at Resolver._throwModNotFoundError (../jest/node_modules/jest-resolve/build/resolver.js:487:11)
          at async Promise.all (index 0)
          at async Promise.all (index 0)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.17 s
Ran all test suites matching /Thing/i.

Additional context

I believe what's going on is that, somehow, when Jest loads (or causes to be loaded) an ESM module due to an import in a test file, the imports binding from the loaded module's package.json is being ignored. For reference, here's what's in it for this example:

{
  "imports": {
    "#x/*": "./export/*.js",
    "#p/*": "./private/*.js"
  }
}

(I don't think the #p binding is necessary for reproduction; I thought it might be handy to pre-emptively answer the question of what the bigger intention is with this arrangement.)

Environment

System:
    OS: macOS 12.4
    CPU: (8) arm64 Apple M1
  Binaries:
    Node: 18.7.0 - /opt/homebrew/bin/node
    npm: 8.15.0 - /opt/homebrew/bin/npm
@SimenB
Copy link
Member

SimenB commented Sep 12, 2022

Duplicate of #12270

@SimenB SimenB marked this as a duplicate of #12270 Sep 12, 2022
@SimenB SimenB closed this as not planned Won't fix, can't repro, duplicate, stale Sep 12, 2022
@danfuzz
Copy link
Author

danfuzz commented Sep 12, 2022

Thanks for the quick response! Apologies, I failed to find the existing issue when I tried to search for similar bugs.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants