jest: transformIgnorePatterns causes errors for npm linked packages
Do you want to request a feature or report a bug? Bug
What is the current behavior? Running simple tests works. Running tests that import npm linked packages causes errors; e.g.,
jest sanity Couldn’t find preset “react-native” relative to directory “demo/sub/ux/node_modules/my-linked-module/node_modules/react-apollo”
(My modules have no direct dep on “react-native”, but there’s a transitive dep via “react-apollo”)
But, babel (and webpack and karma) all work fine. Also, jest works fine in the dependent module (my-linked-module).
babel-node src/web/sanity.test.js OK
If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install
and yarn test
.
Create a dependency on another module via npm link. Import that module in a test (ES6 syntax): Add: “transformIgnorePatterns”: [ “/!node_modules\/my-linked-module/” ] to package.json
What is the expected behavior? It should compile OK
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system. jest: v19.0.2 node: v7.5.0 OSX 10.2
package.json “jest”: { “verbose”: true, “transformIgnorePatterns”: [ “/!node_modules\/my-linked-module/” ] },
.babelrc { “presets”: [ “es2015”, “stage-0”, “react” ],
“env”: { “test”: { “plugins”: [“transform-es2015-modules-commonjs”] } } }
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16
What about this - it solved mine : .babelrc
package.json
@thymikee I debugged Jest and found the cause. transformIgnorePatterns works fine, the problem appears because ScriptTransformer uses a local babelrc configuration file. Main project is aware of Jest, so I have the following in babelrc:
"test": { "plugins": [ "transform-es2015-modules-commonjs" ] }
However scoped sub-projects know nothing about global test environment, so there is no configuration for “test”, therefore transformation doesn’t affect es6 imports. After I updated babelrc with commonjs plugin everything works fine. I don’t know if it’s intended functionality to use local babelrc instead of global?@thymikee it seems the problem might be with bundled babel-jest. Since
I do not specify custom “transform” option. If transformIgnorePatterns option is mentioned but empty it tries to process all packages in node_modules, so generally transformation works, but ignores packages in “scoped” folder
@thymikee I have the same problem, and configuration you provided
"node_modules/(?!react-native|my-linked-module)/"
works fine, however transformation ignores scoped packages, e.g."node_modules/(?!@myscopedpackages)"
won’t be affected by transform module.