-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
babel-jest does not locate babel config when it is in root directory #8006
Comments
See #7185 (comment) |
This was driving me crazy until I finally realized that Jest was just plain ignoring |
@icopp: I'm using an ugly hack now: module.exports = require('../babel.config.js'); It would be really nice if Babel moved forward soon to read its config files like ESLint. |
I am having the same problem. But... it does notice .babelrc in the root directory. |
I'm having the same problem. |
This is my
And my jest config:
|
Which is to say - are you using |
Ok so where in that case should babel.config.js go so that bug doesn't occurre? |
If you're using |
My |
Having the same issue with babel.config.js and jest.config.js on root. |
Perhaps related? babel/babel#11036 |
Having the same issue |
I think I know what this is. If your Jest config sets Stepping through Babel's configuration code, I found myself in the file function findConfigUpwards(rootDir) {
return null;
} Babel can run in a browser (if you're completely insane) so the
"browser": {
"./lib/config/files/index.js": "./lib/config/files/index-browser.js",
"./lib/transform-file.js": "./lib/transform-file-browser.js"
}, Jest's moduleNameMappee: {
'@babel/core/lib/config/files/index-browser.js':
'@babel/core/lib/config/files/index.js'
} That worked for me. |
amazing find @zetlen though at least in my case, "browser" is false |
Aw, too bad. I should have noticed that above. |
Weighing in late, but with a suggestion similar to @morgs32, you can add the following to your module.exports {
...config,
transform: {
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { rootMode: 'upward' }],
},
} Or if you're configuring from the "jest": {
"transform": {
"^.+\\.(js|jsx|ts|tsx)$": ["babel-jest", { "rootMode": "upward" }],
}
} This removes the need for creating an extra file. |
Just weighing in. I have a similar project structure as @mindaugasnakrosis and was facing the exact issue. But my root level babel config was |
Hi, you can specify path in the configuration "babel-jest" like this
|
I manage to fix this error on a yarn2 workspace. I had to replace this in my transform: {
'^.+\\.js?$': 'babel-jest',
// ...otherTransforms
}, by: transform: {
'^.+\\.js?$': '<rootDir>/node_modules/babel-jest',
// ...otherTransforms
}, I think that the reason behind this is that yarn workspace change the working directory in someway |
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 14 days. |
This issue was closed because it has been stalled for 7 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. |
🐛 Bug Report
Versions:
Please tell us about your environment:
Ubuntu
Folder structure
Mono-repo. All projects in packages folder.
When this error occured?
When I moved babel.config.js to root folder out of local scope of package.
Folder structure
Current behavior:
In react-project I launch command:
../../node_modules/.bin/jest -c $(pwd)/jest.config.js --rootDir .
I get an error because I suppose that
babel.config.js
is not found:jest.config.js:
babel.config.js
Additional question:
Is it possible to use one
jest.config.js
for all the packages' tests' the same way likebabel.config.js
. When executing tests search forjest.config.js
UPROOT till it founds it?The text was updated successfully, but these errors were encountered: