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]: Jest not recognizing package.json exports for require (backwards compat with cjs) #12312

Closed
junderw opened this issue Feb 6, 2022 · 3 comments

Comments

@junderw
Copy link

junderw commented Feb 6, 2022

Version

27.4.7

Steps to reproduce

  1. Clone https://github.com/Robin-Hoodie/tiny-secp256k1-repro
  2. yarn install
  3. yarn test:ts

Expected behavior

I expect jest to see the cjs modules pointed to in package.json for tiny-secp256k1

See https://github.com/bitcoinjs/tiny-secp256k1/blob/v2.2.0/package.json#L14-L30

exports["."].node.require in the package.json points to cjs (we ship both cjs AND mjs with mjs as the default (.js extension))

I would expect Jest to notice that "I am a node environment and need require not import, so I will load the cjs"

Actual behavior

Jest tries to load the mjs (.js) files and fails with SyntaxError: Cannot use import statement outside a module

Additional context

No response

Environment

System:
    OS: macOS 11.6.1
    CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
  Binaries:
    Node: 14.18.1 - ~/.nvm/versions/node/v14.18.1/bin/node
    Yarn: 3.1.1 - ~/.nvm/versions/node/v14.18.1/bin/yarn
    npm: 6.14.15 - ~/.nvm/versions/node/v14.18.1/bin/npm
@junderw junderw changed the title [Bug]: [Bug]: Jest not recognizing package.json exports for require (backwards compat with cjs) Feb 6, 2022
@junderw
Copy link
Author

junderw commented Feb 6, 2022

Related: bitcoinjs/tiny-secp256k1#73

@SimenB
Copy link
Member

SimenB commented Feb 7, 2022

Duplicate of #9771 (specifically you can follow #11924 which solves your issue).

You can add main as a fallback for CJS until Jest 28

@SimenB SimenB closed this as completed Feb 7, 2022
@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 Mar 11, 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