Issue with `export class Bug { ... }; export default Bug;` in Babel 7
See original GitHub issueI am seeing this issue with react-native@0.56.0
and metro@0.38.3
(and also metro@0.38.1
).
Here’s the code that causes the issue:
export class Bug {
constructor(props) {
this.test(props);
}
test = (props) => {
// Error-causing line
const test = props.test;
}
}
export default Bug;
The error is:
error: bundling failed: TypeError: Property body[1] of BlockStatement expected node to be of a type ["Statement"] but instead got "ClassExpression"
at validate (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/types/lib/definitions/utils.js:130:13)
at validator (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/types/lib/definitions/utils.js:97:7)
at Object.validate (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/types/lib/definitions/utils.js:177:7)
at validate (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/types/lib/validators/validate.js:17:9)
at builder (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/types/lib/builders/builder.js:46:27)
at Object.BlockStatement (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/types/lib/builders/generated/index.js:245:31)
at NodePath.replaceExpressionWithStatements (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/traverse/lib/path/replacement.js:212:57)
at NodePath.insertBefore (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/traverse/lib/path/modification.js:47:17)
at NodePath.unshiftContainer (/Users/ashoat/Dropbox/src/rn56babelbug/node_modules/@babel/traverse/lib/path/modification.js:204:15)
I’ve created a repo with this minimal repro here. I attempted to repro the issue without Metro, by setting up a Babel project with the same code and babel-preset-react-native
here, but was unable to repro. My conclusion is that the issue has something to do with how Metro consumes Babel.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
[Bug]: Some issue in @babel/parser version 7.20.0 #15085
SyntaxError: A decorated export must export a class declaration. at instantiate /node_modules/@babel/parser/src/parse-error/credentials.ts:62:21.
Read more >@babel/plugin-proposal-export-default-from - Package Manager
Fast, reliable, and secure dependency management.
Read more >Troubleshooting common React Native bugs - LogRocket Blog
This troubleshooting guide shares how to easily find and address common React Native bugs. See common error examples.
Read more >babel/preset-env
By default @babel/preset-env uses caller data to determine whether ES modules and module features (e.g. import() ) should be transformed. Generally caller data ......
Read more >Trouble Installing babel's "plugin-proposal-export-default-from"
I did that and now the command works to install the packages. I found this old discussion where people mention it being a...
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
I think this may be fixed via Babel 7.0 and Metro 0.44.x (once this is merged https://github.com/facebook/metro/pull/233)
Yes, we can close this one already! 😄