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.

ES Numeric Separators broken by babel (Unexpected token: name (_000))

See original GitHub issue

Do you want to request a feature or report a bug? Bug / improvement for metro-react-native-babel-preset

What is the current behavior?

Error: Unexpected token: name (_000) in file App.tsx at 16:25

A build error that makes little sense in the context of a larger code base. The line:col isn’t true to the original code, I had to console.log from within /metro/src/JSTransformer/worker.js to find the problematic line.

If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.

  • react-native init MyApp --template react-native-template-typescript
  • Use ES Numeric Separators syntax in your code, e.g. const thousand = 1_000;
  • Try to bundle the project for release

Minimal repository reproducing the issue:

  • git clone https://github.com/westphalen/metro-babel-preset-numeric-separators
  • yarn install
  • yarn build

What is the expected behavior? Since the boilerplate project is set up to support TypeScript and es2017/esnext, one would expect that ES Numeric Separators were supported out of the box.

Solution yarn install @babel/plugin-proposal-numeric-separator

Update babel.config.js with this line:

  plugins: ['@babel/plugin-proposal-numeric-separator'],

Would suggest this plugin is included by default in metro-react-native-babel-preset

Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.

  • macOS 10.15.7
  • node -v v10.22.0
  • "metro-react-native-babel-preset": "0.63.0"
  • metro "0.58.0"

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:11
  • Comments:25 (5 by maintainers)

github_iconTop GitHub Comments

18reactions
felipemillhousecommented, Nov 25, 2021

on metro.config.js I just included the babel plugin and it worked for me

module.exports = {
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: true,
      },
    }),
    plugins: ['@babel/plugin-proposal-numeric-separator'],
  },
}
8reactions
Dean177commented, Feb 4, 2022

Just switch to https://github.com/omgovich/colord similar api, better performance, smaller size

Read more comments on GitHub >

github_iconTop Results From Across the Web

ES Numeric Separators broken by babel (Unexpected token: name ...
Do you want to request a feature or report a bug? ... What is the current behavior? Error: Unexpected token: name (_000) in...
Read more >
babel-loader jsx SyntaxError: Unexpected token [duplicate]
I found a weird error in my hello world web app. I'm using babel-loader in webpack to help me convert jsx into js,...
Read more >
Bug listing with status RESOLVED with resolution TEST ...
Bug:233 - "Emacs segfaults when merged through the sandbox." status:RESOLVED resolution:TEST-REQUEST severity:critical · Bug:3888 - "yenta_socket module not ...
Read more >
Content Types - ESBuild
Numeric separators, esnext, 1_000_000 ... The private member transform (for the #name syntax) uses WeakMap and WeakSet to preserve the privacy properties of ......
Read more >
Untitled
isArray(t))return 0===t.length;switch(typeof t){case"string":return""===t;case"boolean":case"number":case"function":return!1;case"object":return ...
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