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 doesn't pick up babel config in monorepo setup when upgrading to Jest 28 #12768

Closed
jimmycallin opened this issue Apr 28, 2022 · 4 comments

Comments

@jimmycallin
Copy link

Version

28.0.2

Steps to reproduce

  1. Open codesandbox: https://codesandbox.io/s/strange-dubinsky-9i4b23?file=/package.json
  2. Run yarn jest
  3. Notice it failing
  4. If downgrading jest in root package.json to 27.5.1, it works

Expected behavior

I expect it to pass as in jest 27

Actual behavior

    Details:

    /sandbox/node_modules/uuid/dist/esm-browser/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export { default as v1 } from'./v1.js';
                            ^^^^^^

    SyntaxError: Unexpected token 'export'

Additional context

I assume it has something to do with the babelRoot update, but I cannot figure out what changes I need to make to my setup to make it work.

Environment

System:
    OS: Linux 5.4 Debian GNU/Linux 10 (buster) 10 (buster)
    CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
  Binaries:
    Node: 14.18.1 - ~/.nvm/versions/node/v14.18.1/bin/node
    Yarn: 3.2.0 - ~/.nvm/versions/node/v14.18.1/bin/yarn
    npm: 6.14.15 - ~/.nvm/versions/node/v14.18.1/bin/npm
  npmPackages:
    jest: ^28.0.2 => 28.0.2
@SimenB
Copy link
Member

SimenB commented Apr 28, 2022

I think you're just hitting uuidjs/uuid#616, i.e. exports resolving to ESM instead of CJS like in jest 27.

If you want to transpile it, you need to enable transpilation for node_module, which is disabled by default (see https://jestjs.io/docs/configuration#transformignorepatterns-arraystring)

@SimenB SimenB closed this as completed Apr 28, 2022
@wkillerud
Copy link

Posting this here since others in my situation may come looking at this issue.

I was having trouble using Jest 28 in a monorepo setting with TypeScript. In my particular case, the project tree looked something like this:

jest/
    setupTest.ts
    jest.unit.js
packages/
babel.config.js

Our test script: jest -c './jest/jest.unit.js'

I think we maybe had several Jest configs at some point, and so used a folder to clean up the root somewhat.

After the changes in #12689, it looks like babel is configured to not look for a config file further up than the folder of the Jest configuration file. In our case, that means jest/ is the end of the line. Babel would not find babel.config.js, and things would break on the first import.

When I moved the Jest config to the same directory as our Babel config everything started working just fine:

jest/
    setupTest.ts
packages/
babel.config.js
jest.config.js

@SimenB
Copy link
Member

SimenB commented May 6, 2022

You can also specify rootDir in your config if you don't wanna move the file to the root

@github-actions
Copy link

github-actions bot commented Jun 6, 2022

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 Jun 6, 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

3 participants