Skip to content

[Bug]: Jest not recognizing package.json exports for require (backwards compat with cjs) #12312

@junderw

Description

@junderw

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions