ES Numeric Separators broken by babel (Unexpected token: name (_000))
See original GitHub issueDo 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:
- Created 3 years ago
- Reactions:11
- Comments:25 (5 by maintainers)
Top GitHub Comments
on
metro.config.js
I just included the babel plugin and it worked for meJust switch to https://github.com/omgovich/colord similar api, better performance, smaller size