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.

Issue with `export class Bug { ... }; export default Bug;` in Babel 7

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kelsetcommented, Aug 28, 2018

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)

0reactions
rafecacommented, Sep 6, 2018

Yes, we can close this one already! 😄

Read more comments on GitHub >

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

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