react / react/metro

[Help wanted] App broken when setting corejs=3 for '@babel/plugin-transform-runtime'

Open
#1,090 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
5.6k
Forks
696
Avg merge
8m
Merged PRs (30d)
7

Description

Do you want to request a feature or report a bug?
bug

What is the current behavior?
In the file babel.config.js, I wrote the following code:

plugins: ['@babel/plugin-transform-runtime', { helpers: true, corejs: 3 }]

And the bundle code is as shown:

!(function(e){"use strict";var r=require("@babel/runtime-corejs3/core-js-stable/object/create"),t=(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"),require("@babel/runtime-corejs3/core-js-stable/instance/map"),require("@babel/runtime-corejs3/core-js-stable/instance/slice"),require("@babel/runtime-corejs3/core-js-stable/map")),i=require("@babel/runtime-corejs3/core-js-stable/instance/for-each");require("@babel/runtime-corejs3/core-js-stable/set"),require("@babel/runtime-corejs3/core-js-stable/instance/reverse"),require("@babel/runtime-corejs3/core-js-stable/set-timeout"),require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");e.__r=u,e[__METRO_GLOBAL_PREFIX__+"__d"]=function(e,r,t){if(null!=o[r])return;

And the app went broken, showing exception info like "require is undefined"

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: 0.68
  • metro-react-native-babel-preset: 0.72.1

What is the expected behavior?
The babel plugin can import core-js normaly as before.

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the babel.config.js plugin configuration and the generated bundle shown in the report. Reproduce the failure using React Native 0.68 and metro-react-native-babel-preset 0.72.1, then trace why the generated core-js runtime imports leave require undefined. Done means the app bundles and runs without that exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
babel, javascript, react-native
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.