Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
In Jest we can configure
transformIgnorePatterns
to ignore files to be transpiled, which defaults to
"/node_modules/"
. However, if a dependency is not translated when it is published, such as
/node_modules/atest
, according to the instructions on the official website, it should be configured to
transformIgnorePatterns
, which feels contrary to the "ignored" meaning of this configuration.
I want to know which files are translated and which files are ignored and not translated by pressing the configuration file below.
module.exports = {
// ...
transformIgnorePatterns: ['/node_modules/atest']
// ...
Possible answer 1: Dependencies in node_modules except atest are transpiled
Possible answer 2: Only atest in node_modules is transpiled, the rest of the dependencies are not transpiled
From the doc, the transformIgnorePatterns option has default value: ["/node_modules/", "\\.pnp\\.[^\\\/]+$"]
It means:
If the file path matches any of the patterns, it will not be transformed.
So, the packages inside the node_modules directory will NOT be transformed by default.
Now, you have a package named atest which is not a pre-compiled package, you need to transform it using babel and don't transform other packages inside node_modules. So the configuration should be:
"transformIgnorePatterns": ["/node_modules/(?!(atest)/)"]
Test paths:
/node_modules/atest/index.js
/node_modules/react/index.js
/node_modules/lodash/index.js
/node_modules/dayjs/index.js
The /node_modules/atest will be excluded from transformIgnorePatterns configuration which means it will be transformed.
See the regexp test
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.