question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BabelConfig with rootMode: "upward" not loading babel config files

See original GitHub issue

A 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

https://github.com/arvigeus/monotest

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
arvigeuscommented, Jan 13, 2020

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.

1reaction
ahnpnlcommented, Jan 12, 2020

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 your babelrc in subpackages because ts-jest babel config is on global level. So when you specify ts-jest config to use babel, it only searches in the root folder (by default) or it searches based on specifying string path or use require. 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:

globals: {
    'ts-jest': {
      babelConfig: {
        'plugins': [
          [
            'macros',
            {
              'styledComponents': {
                'pure': true,
              },
            },
          ],
        ],
        rootMode: 'upward',
      },
    },
  },

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 on babelrcRoots in the root babel config ?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found