Next.js Discord

Discord Forum

Adjusting transformIgnorePatterns to also exclude some `node_modules`

Unanswered
Yellowhead catfish posted this in #help-forum
Open in Discord
Yellowhead catfishOP
Hey folks! I have a problem with Next/Jest configuration. Sorry for the long-read.

I am using a library @t3-oss/env-nextjs and everything was working except in the Jest tests. The [solution](https://www.reddit.com/r/nextjs/comments/1d6cuvg/comment/l6sfblu/?utm_source=share&utm_medium=mweb3x&utm_name=mweb3xcss&utm_term=1&utm_content=share_button) I found did the trick, but it seems weird to update Next.js config only to make Jest tests run.

Adding transformIgnorePatterns to the Jest config doesn'tt work. Next/Jest assumes that users would never ignore any of the node_modules themselves. Here is why I think this is the case:

1. The [code](https://github.com/vercel/next.js/blob/09a2167b0a970757606b7f91ff2d470f77f13f8c/packages/next/src/build/jest/jest.ts#L173-L181) in packages/next/src/build/jest/jest.ts is effectively always adding /node_modules/ to the transformIgnorePatterns so [that](https://github.com/vercel/next.js/blob/09a2167b0a970757606b7f91ff2d470f77f13f8c/packages/next/src/build/jest/jest.ts#L185-L187) "Custom config can append to transformIgnorePatterns but not modify it..."

2. If I am to add a library like Jest is recommending, it does not work [because](https://jestjs.io/docs/configuration#transformignorepatterns-arraystring):
transformIgnorePatterns
Providing regexp patterns that overlap with each other may result in files not being transformed that you expected to be transformed.
..this also [here](https://jestjs.io/docs/tutorial-react-native#transformignorepatterns-customization):
transformIgnorePatterns will exclude a file from transformation if the path matches against any pattern provided. Splitting into multiple patterns could therefore have unintended results if you are not careful

My question is, is this intended behavior that I can't adjust transpilation exclusion for a library from node_modules or is that just a bug in Next.js?

Thanks in advance!

0 Replies