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]: getExportsOfCjs resolves reexports using wrong condition #13148

Closed
anomiex opened this issue Aug 18, 2022 · 3 comments
Closed

[Bug]: getExportsOfCjs resolves reexports using wrong condition #13148

anomiex opened this issue Aug 18, 2022 · 3 comments

Comments

@anomiex
Copy link

anomiex commented Aug 18, 2022

Version

28.1.3

Steps to reproduce

  1. Extract the minimal reproduction from this zip file
  2. Run yarn install
  3. Run yarn test

Expected behavior

All tests pass

Actual behavior

One test fails

 FAIL  test/a.test.mjs
  ● Test suite failed to run

    Unexpected export statement in CJS module.
      at @:1:8

      at @:1:8
      at throwIfExportStatement (node_modules/cjs-module-lexer/lexer.js:1189:9)
      at parseSource (node_modules/cjs-module-lexer/lexer.js:155:13)
      at parseCJS (node_modules/cjs-module-lexer/lexer.js:43:5)
          at Array.forEach (<anonymous>)

Additional context

This appears to be because this code uses esmConditions rather than cjsConditions, so the resolver returns an ESM module for a require() which then fails to parse as CJS.
https://github.com/facebook/jest/blob/7d8d01c4854aa83e82cc11cefdd084a7d9b8bdfc/packages/jest-runtime/src/index.ts#L795-L797
Changing that to cjsConditions makes the test pass.

Environment

System:
    OS: Linux 5.18 Debian GNU/Linux bookworm/sid
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
  Binaries:
    Node: 16.17.0 - /usr/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 8.15.0 - /usr/bin/npm
  npmPackages:
    jest: ^28.1.3 => 28.1.3
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Sep 17, 2022
@SimenB
Copy link
Member

SimenB commented Sep 18, 2022

Duplicate of #12759 (although this issue went above and beyond and identified the buggy code!), fixed in #13170

@SimenB SimenB closed this as completed Sep 18, 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 Oct 19, 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