You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Babel plugin: a namespace or default import of react-native-paper fails the build #5227
With Paper's optional Babel plugin enabled (react-native-paper/babel, as in the Bundle size section of Getting Started), any file that imports Paper as a namespace or with a default import fails to compile:
App.js: Cannot read properties of undefined (reading 'name')
The plugin rewrites each import specifier with mappings[specifier.imported.name] (src/babel/index.js, line 20). Only named import specifiers have imported. Namespace and default specifiers don't, so specifier.imported is undefined. A named import such as import { Button } from 'react-native-paper' works.
Since the plugin usually runs only in the production Babel env, the app works in development and the crash only shows up in a release build.
Expected behaviour
The plugin leaves namespace and default imports of react-native-paper as they are, or rewrites only what it can, and the file compiles. Tests cover a namespace import, a default import and a default import mixed with named ones.
How to reproduce?
Add the plugin as Getting Started's Bundle size section shows:
In any file, write import * as Paper from 'react-native-paper'; and use Paper.Button.
Make a release bundle, for example npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output out.js.
The same error comes from running the plugin alone through @babel/core on either line above.
What have you tried so far?
Using only named imports avoids it. #3817 reported the namespace case for release bundles in 2023 and was closed in 2024, but the plugin still reads specifier.imported.name without a check on main. #4874 (re-exports aren't rewritten) and its PR #4969 touch the same code, so they fit in the same fix.
Your Environment
software
version
react-native-paper
6.0.0-alpha.3 (main at 8787d4b); 5.x has the same code
Activity