jest
jest copied to clipboard
Files are not transformed when there is nested `package.json` file
🐛 Bug Report
Let's say I have second package.json
file in the director my-package
. When I run tests using jest
from the project root directory the files within my-package
dir are not transformed.
Error message:
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
To Reproduce
Steps to reproduce the behavior:
- create new directory within your project
- create new package.json files in the created dir
- create test file using ES6 imports
- run tests from the root dir
- error
Jest encountered an unexpected token
Expected behavior
Files within directories containing another package.json file should be transformed.
envinfo
System:
OS: macOS Mojave 10.14.6
CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
Binaries:
Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node
Yarn: 1.19.1 - /usr/local/bin/yarn
npm: 6.13.4 - ~/.nvm/versions/node/v12.16.1/bin/npm
npmPackages:
jest: ^24.8.0 => 24.8.0
I got similar error and created a new issue with reproduction detail (ex. link to repo). Please see https://github.com/facebook/jest/issues/10647
@latata
I found the solution for my own case.
If you are using .babelrc.js
, https://github.com/facebook/jest/issues/10647#issuecomment-747794046 may help you.
funny ... renaming a file to fix such an issue worked surprisingly well, as mentioned in https://github.com/facebook/jest/issues/9996#issuecomment-747795051 Thanks :)
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
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.