jest, unable to load babel plugin
See original GitHub issueHi, 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:
- Created 5 years ago
- Reactions:2
- Comments:6
Top 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 >
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 Free
Top 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
@mnemanja That looks like you’re not installing packages you need. Try doing
yarn add babel-preset-react-app -D
ornpm 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:
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 😃.
I resolved my issue too. The problem was my
.babelrc
config.I use the
grommet
import babel plugin that seems incompatible withbabel-jest
transform. When this plugin is set transform process fail without error or any other info about it.I removed the plugin for now.