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.

jest, unable to load babel plugin

See original GitHub issue

Hi, thanks for the great tool. I am using the react-app-rewire-typescript-babel-preset and I am trying to add a babel plugin that I need for jest.

The problem is, that the babel config is not picked up from .babelrc and not from package.json. This is my config-overrides.js

const { compose, injectBabelPlugin } = require('react-app-rewired');
const {
  rewireWebpack: rewireTypescript,
  rewireJest: rewireTypescriptJest
} = require('react-app-rewire-typescript-babel-preset');
const rewireReactHotLoader = require('react-app-rewire-hot-loader');
const rewireStyledComponents = require('react-app-rewire-styled-components');
const rewireGqlTag = require('react-app-rewire-graphql-tag');

// JSX CONTROLS

function rewireJsxControlStatements(config, env, styledComponentsPluginOptions = {}) {
  return injectBabelPlugin(
    ['module:jsx-control-statements', styledComponentsPluginOptions],
    config
  );
}

module.exports = {
  webpack: function(config, env) {
    const rewires = compose(
      rewireTypescript,
      rewireReactHotLoader,
      rewireJsxControlStatements,
      rewireStyledComponents,
      rewireGqlTag
    );

    return rewires(config, env);
  },
  jest: function(config, env) {
    const rewires = compose(rewireTypescriptJest);
    return rewires(config, env);
  }
};

And this is my .babelrc

{
  "plugins": ["jsx-control-statements"]
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

3reactions
dawnmistcommented, May 31, 2018

@mnemanja That looks like you’re not installing packages you need. Try doing yarn add babel-preset-react-app -D or npm install babel-preset-react-app --save-dev to add the missing babel preset package (and the same for anything else missing) to your package.json.

@SinHouse Yes, you cannot add babel packages inside the config-overrides jest section. I do currently run jest with babel plugins set in the package.json babel section, so I know it is possible to do (our tests won’t compile without those plugins, so they are definitely in use). Our current babel settings is:

{
  "babel": {
    "env": {
      "test": {
        "plugins": [
          "transform-es2015-modules-commonjs",
          "dynamic-import-node"
        ]
      }
    }
  }
}

Can you create a separate issue with a sample repository with the list of plugins you’re trying to use, since your issue isn’t the same as the original one? Without the sample repository it is impossible to debug what is going wrong.

@tomitrescak Thank you for clarifying that it was the rewire that was at fault 😃.

0reactions
uxtechiecommented, May 31, 2018

I resolved my issue too. The problem was my .babelrc config.

I use the grommet import babel plugin that seems incompatible with babel-jest transform. When this plugin is set transform process fail without error or any other info about it.

I removed the plugin for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test Jest with babel-plugin-import - Stack Overflow
I'm new to the Jest library so I'm unsure the proper way to import or get around that issue? Example: Test Suite failed...
Read more >
Configuring Jest
This is due to the need to load the actual transformers (e.g. babel or typescript ) to perform transformation. setup.js. module.exports = async ......
Read more >
babel/preset-react
Automatic runtime (since v7.9.0 ) adds the functionality for these plugins automatically when the development option is enabled. If you have automatic runtime ......
Read more >
babel-plugin-jest-hoist - npm
Start using babel-plugin-jest-hoist in your project by running `npm i babel-plugin-jest-hoist`. There are 346 other projects in the npm ...
Read more >
babel-jest | Yarn - Package Manager
If you are already using jest-cli , add babel-jest and it will automatically compile JavaScript code using Babel. yarn add --dev babel-jest @babel/core....
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