Repository navigation
Conversation
The plugin read `specifier.imported.name` for every specifier, but only named import specifiers have `imported`. A namespace or default import of react-native-paper failed the build with "Cannot read properties of undefined (reading 'name')". Namespace and default imports now stay on the full index, while named imports in the same statement are still rewritten. Fixes #5227
|
Found potential problems with the pull request:
|
Apex Sentinel · ✅ Approve · review of
|
| Where | Finding |
|---|---|
src/babel/index.js:20 |
Default import of react-native-paper now compiles to an always-undefined binding |
2 findings below minor hidden (user_settings.min_severity).
Reviewed with this repository's own Sentinel configuration (295f36b5e27b).
💬 Talking to Sentinel
In a finding's thread, reply with:
| Command | What it does |
|---|---|
@apex-sentinel-staging note <context> |
Adds context; Sentinel re-checks the cited code |
@apex-sentinel-staging pivot <why> |
Says the finding is wrong; Sentinel re-checks the cited code |
@apex-sentinel-staging like |
Marks the finding as useful |
@apex-sentinel-staging dislike <why> |
Marks it as not useful, so it is not raised again |
On this conversation, comment @apex-sentinel-staging review to run a full review once again.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 22a1f09. The verdict and the full list are in the summary comment.
| // Only a named import maps to a module. A namespace or default | ||
| // import (`import * as Paper`, `import Paper`) has no `imported` | ||
| // name, so it stays on the index. | ||
| const mapping = t.isImportSpecifier(specifier) | ||
| ? mappings[specifier.imported.name] | ||
| : undefined; |
There was a problem hiding this comment.
🟡 Minor · Default import of react-native-paper now compiles to an always-undefined binding
import Paper from 'react-native-paper' compiles and rewrites to import Paper from "react-native-paper/lib/module/index.js", but neither src/index.tsx nor lib/module/index.js exports default, so Paper is undefined at runtime — the Paper.Button is not a component render error replaces the previous build-time failure. The new guard treats ImportDefaultSpecifier the same as a namespace import and keeps it on the index. The default-import and default-and-namespace-import fixtures lock this output in as expected behavior.
Suggested change
Either emit a plugin warning when a default specifier for react-native-paper is seen (e.g. path.buildCodeFrameError), or state in the getting-started note that react-native-paper has no default export so import Paper from 'react-native-paper' yields undefined.
Details
persona: javascript, senior-developer
Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.
Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.
The plugin read
specifier.imported.namefor every specifier, but only named import specifiers haveimported. A namespace or default import of react-native-paper failed the build with "Cannot read properties of undefined (reading 'name')".Namespace and default imports now stay on the full index, while named imports in the same statement are still rewritten.
Fixes #5227
Motivation
With the optional Babel plugin (
react-native-paper/babel) enabled, a file that imports Paper as a namespace or with a default import fails to compile:Apps usually enable the plugin only in the production Babel env, so the app works in development and the error first shows up in a release build. Named imports aren't affected.
After this change, namespace and default imports compile and load the full library. Named imports in the same statement are still rewritten. The Getting Started guide now says that a namespace import doesn't reduce the bundle size.
Related issue
Fixes #5227. This is the same crash as #3817, which was closed in 2024 without a fix.
Screenshots / Videos
N/A
Test plan
Build the plugin with
yarn prepack.From the repository root, run:
On
mainthis throwsCannot read properties of undefined (reading 'name'). On this branch it prints: