BabelConfig with rootMode: "upward" not loading babel config files
See original GitHub issueA simple monorepo with the following config:
// package/ui/jest.config.js
{
globals: {
"ts-jest": {
babelConfig: {
rootMode: "upward"
}
},
preset: "ts-jest",
transform: {
"^.+\\.jsx?$": ["babel-jest", { rootMode: "upward" }]
}
}
When I run yarn test
it works as expected. When I run yarn lerna run test
, ts-jest
fails to load babel configs. If I use babel-jest
instead of ts-jest
, it works fine. The only way to make it work is to manually pass the entire babel config to globals[ts-jest].babelConfig
.
Maybe something like globals[ts-jest].babelConfig.babelrc: true
would be nice in such case to allow loading configs. It didn’t worked with globals[ts-jest].babelConfig: true
Minimal repo
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (1 by maintainers)
Top Results From Across the Web
Config Files - Babel
There are a few ways to do that, but the recommended way is the "rootMode" option with "upward" , which will make Babel...
Read more >babeljs - Babel: root programmatic options - Stack Overflow
I added a top-level babel.config.js as part of Babel's monorepo instructions. I had rootMode: "upwards" in these three places:.
Read more >A brand new website interface for an even better experience!
BabelConfig with rootMode: "upward" not loading babel config files.
Read more >Why is my webpack bundle successfully built on host machine ...
As I mentioned in the update section of my question the solution was to move all babel related packages to devDependencies section of...
Read more >Setting up a custom .babelrc file without ejecting a React App ...
In this video we create a custom .babelrc file and configure a create react application to incoperate it into its build process.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Isn’t it possible to delegate this to
babel-jest
when it comes to it? Otherwise you are reimplementing logic. I am thinking about some general solution, not just my problem in particular.what I can see from the log is actually
babelrc
wasn’t loaded but only root babel config is loaded (you can search for"plugins"
in your log).So the main issue here is
ts-jest
doesn’t know about yourbabelrc
in subpackages becausets-jest
babel config is on global level. So when you specifyts-jest
config to use babel, it only searches in the root folder (by default) or it searches based on specifying string path or userequire
.ts-jest
doesn’t search for the whole project to find other babel config. Therefore it throws the error like you saw.So temporarily workaround is you copy the content of babel config in your subpackages and paste to
ts-jest
babel config, for example:The question here is how does
ts-jest
know when to search for the whole project to find other babel configs. The idea of providing a subpackage babel config is the easiest implementation, but is it a good way to go ?What do you think @kulshekhar ? I think perhaps for loading babel config, if user specifies
rootMode: 'upward'
we can somehow look for babel config in the whole project based on ? But this will create a question is how to find the config in subpackages quickly, can we rely onbabelrcRoots
in the root babel config ?