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

Node 22.12.0 incompatible with jest #3871

Closed
busma13 opened this issue Dec 11, 2024 · 6 comments
Closed

Node 22.12.0 incompatible with jest #3871

busma13 opened this issue Dec 11, 2024 · 6 comments

Comments

@busma13
Copy link
Contributor

busma13 commented Dec 11, 2024

jestjs/jest#15363
prettier/prettier#16930

If I am reading these issues correctly, it looks like jest.config.ts will fail when it tries to import a package that imports prettier if running node v22.12.0 or v23. xlucene-parser has prettier as a nested dependency.

We need to pin node 22 at 22.11.0 in CI before github starts using node 22.12.0.

The base-docker-image already contains node 22.12.0 and It is used in teraslice v2.9.1 and v2.9.2. I will test to see if I can find any issues with how these versions function.

@godber
Copy link
Member

godber commented Dec 11, 2024

Can you please describe the impact of this issue?

We need to pin node 22 at 22.11.0 in CI before github starts using node 22.12.0.

Pinning is only a temporary solution to the problem since as you point out, we are already using this version of node. Unless the p

@busma13
Copy link
Contributor Author

busma13 commented Dec 11, 2024

If the CI runners begin using node v22.12.0 as the default node 20 version, all jest test commands will then fail with this error: Error [ERR_REQUIRE_ASYNC_MODULE]: require() cannot be used on an ESM graph with top-level await. Use import() instead. To see where the top-level await comes from, use --experimental-print-required-tla.

@sotojn
Copy link
Contributor

sotojn commented Dec 11, 2024

For some reason node 22.12.0 won't allow top level awaits with the jest config. I've updated the jest configs to not use a top level await and it fixes the issue:

New jest config in all the packages

import { fileURLToPath } from 'node:url';
import baseConfig from '../../jest.config.base.js';

const dirPath = fileURLToPath(new URL('.', import.meta.url));

const config = baseConfig(dirPath);

export default config;

@busma13
Copy link
Contributor Author

busma13 commented Dec 11, 2024

This was not actually related to prettier at all.

@busma13
Copy link
Contributor Author

busma13 commented Dec 12, 2024

After removing top level awaits from the jest.config.tss we ran into an issue with how a nested dependency unicorn-magic@0.3.0 was being imported into jest within e2e. The temporary fix is to create a patch of it's package.json.

@busma13 busma13 changed the title Node 22.12.0 incompatible with jest and/or prettier Node 22.12.0 incompatible with jest Dec 12, 2024
@busma13
Copy link
Contributor Author

busma13 commented Dec 16, 2024

I figured out why we were having issues with unicorn-magic. We are overriding the default transformIgnorePatterns array in jest.config.base.js with an empty array.
The default is `["/node_modules/", "\.pnp\.[^\\/]+$"]. Since we removed that we were running our @swc transform on all of our node_modules unnecessarily, and in this case it broke something.

godber pushed a commit that referenced this issue Dec 16, 2024
This PR makes the following changes:
- In `jest.config.base.js` explicitly set `transformIgnorePatterns` to
the default (`['/node_modules/', '\\.pnp\\.[^\\/]+$']`), which will skip
running transforms on node-modules or pnp files. We were overriding the
default with an empty array. Standard practice is to only transform
specific dependencies if there is a need.
- Remove patch for `unicorn-magic` dependency, as it is no longer being
broken by the jest transform.
- Add README to `./patches` explaining how to make a patch using
`patch-package`. This also prevents the `patches` directory from being
removed if there are no patches, breaking the docker build.

Ref: #3871, #3874
@busma13 busma13 closed this as completed Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants