Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New validation in Babel 7.7.0 breaks Metro #481

Closed
leonid-shevtsov opened this issue Nov 5, 2019 · 3 comments
Closed

New validation in Babel 7.7.0 breaks Metro #481

leonid-shevtsov opened this issue Nov 5, 2019 · 3 comments

Comments

@leonid-shevtsov
Copy link

leonid-shevtsov commented Nov 5, 2019

Babel 7.7.0 will throw an error for an empty Identifier node: babel/babel#10621

This breaks a specific place in Metro:
https://github.com/facebook/metro/blob/master/packages/metro/src/ModuleGraph/worker/JsFileWrapping.js#L81

function functionFromProgram(
  program: Object,
  parameters: $ReadOnlyArray<string>,
): Object {
  return t.functionExpression(
    t.identifier(''),
    parameters.map(makeIdentifier),
    t.blockStatement(program.body, program.directives),
  );
}

Replacing the empty string with anything but empty resolves the issue.

I don't have enough familiarity with Metro to suggest a proper identifier. :)

Babel: 7.7.0
Metro: 0.57
Yarn: 1.19.1

Metro config:

module.exports = {
  resolver: { sourceExts: ['js', 'jsx'] },
};

Babel config:

{
  "presets": ["module:metro-react-native-babel-preset"],
  "plugins": [
    [
      "transform-inline-environment-variables",
      {
        "include": ["SENTRY_DSN"]
      }
    ]
  ]
}
@loganfsmyth
Copy link

Instead of t.identifier(''), Metro should be passing null as the identifier. Looks like this has been working by chance until now because Babel didn't have validation and no other plugins happened to trip over the empty identifier.

@nicolo-ribaudo
Copy link

We plan to re-introduce this validation in Babel 8 (babel/babel#10746).

@MichaReiser
Copy link

Closing as this has been fixed in ed8a04f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants