Babel 7 and Jest (you need both babel 6 and babel 7 to get them to work)
See original GitHub issueBug Report
Current Behavior
Migrating from babel 6x to 7.x First tried manually, then using npx babel-upgrade
. Getting the same error thrown for both cases. Error:
Support for the experimental syntax 'classProperties' isn't currently enabled (52:20):
Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel config to enable transformation.
I did what the error asks me to do but it makes zero difference
Input Code
export class Foo extends React.Component {
static propTypes = {
}
}
relevant sections of package.json
"devDependencies": {
"@babel/core": "7.1.2",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-decorators": "^7.0.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-proposal-function-sent": "^7.0.0",
"@babel/plugin-proposal-json-strings": "^7.0.0",
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/preset-env": "7.0.0",
"@babel/preset-react": "7.0.0",
"@babel/runtime": "7.1.2",
}
Expected behavior/code It should compile as expected
Babel Configuration (package.json section)
{
"plugins": [
"react-hot-loader/babel",
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-json-strings",
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
"@babel/plugin-proposal-throw-expressions"
],
"presets": [
[
"@babel/preset-env",
{
"modules": false
}
],
"@babel/preset-react"
],
}
Environment
- Babel version(s): as listed in devDependencies above
- Node/npm version: Node 8.11.3/npm 5.6.0
- Using Yarn 1.5.1 with workspaces
- OS: OSX 10.14
- Monorepo: yes, devDependecies are defined in the root package.json only
- How you are using Babel: loader
Tried using .babelrc.js
file as well, but it makes no difference and that one particular plugin is never applied/recognized as being defined in plugins
Issue Analytics
- State:
- Created 5 years ago
- Comments:19 (6 by maintainers)
Top Results From Across the Web
Upgrade to Babel 7
In Babel 7, this command has been split out into its own @babel/node package, so if you are using that command, you'll want...
Read more >babel@7 and jest configuration - Stack Overflow
I believe I have found a working solution (no thanks to the Jest team providing broken documentation and evading GitHub issues around this ......
Read more >React + webpack4 + babel 7 (Jest included) - Medium
We will require a babel loader for jest called, babel-jest and let's use react-test-renderer as the library for snapshots. This article will ...
Read more >Jest Getting Started - w3resource
Jest 24 has dropped the support for Babel 6. It is highly recommended that you to upgrade to Babel 7, which is actively...
Read more >babel-jest - npm
Jest plugin to use babel for transformation.. Latest version: 29.3.1, ... Start using babel-jest in your project by running `npm i babel-jest`.
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
With a monorepo you need to use
babel.config.js
instead of.babelrc
babel-plugin-dynamic-import-node
works on both babel 6 and 7 as of version 2.2.0.@babel/xxx
are “official” plugins for babel 7+, which are all located in this repository. Third party plugins (aka. “unofficial”) likebabel-plugin-dynamic-import-node
will not be in the namespace “@babel/” even if they work for babel 7.