Metro resolver loop with react-native-worklets bundle mode: "Maximum call stack size exceeded" on launch (`get NativeModules`)
維護者通常 3 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 30/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- javascript, react-native
- 領域
- build-system, mobile
研究方向
The loop involves two Metro resolvers: nativeResolver in react-native-css, which handles react-native imports from internal origins, and the worklets bundle-mode shim at react-native-worklets/bundleMode/shims/reactNativeShim.js. Start by reading how nativeResolver delegates to the parent resolver for internal origins, then trace the cycle through react-native-css/dist/commonjs/components/index.cjs. Done means the reproduction in the issue no longer overflows the stack when both wrappers are applied, in either order, and the workaround in the issue is no longer needed.
由索引模型根據 Issue 內容生成。
描述
Describe the bug
With react-native-worklets' bundle mode enabled (getBundleModeMetroConfig), the app crashes on launch, before AppRegistry registers anything:
RangeError: Maximum call stack size exceeded (native stack depth)
Invariant Violation: "main" has not been registered.
The stack is get NativeModules repeated, from the lazy getters in react-native-css/dist/commonjs/components/index.cjs.
Cause
Two Metro resolvers both rewrite react-native, and react-native-css hands its own react-native imports to the resolver below it:
- App code imports
react-native. Worklets bundle mode resolves it toreact-native-worklets/bundleMode/shims/reactNativeShim.js. - The shim runs
module.exports = require('react-native'). react-native-css'snativeResolverredirects that toreact-native-css/components. react-native-css/components/index.cjsimportsreact-native. Because the origin is internal,nativeResolverreturns the parent resolver's result, and the parent (worklets) sends it back to the shim.- The shim's exports are the react-native-css components, whose getters call
require('react-native'), which returns the shim again. The getters recurse forever.
It loops whichever order the two configs are applied in. nativeResolver already exempts react-native/index.js as an origin. The internal-origin path has a similar problem: it trusts the parent resolver to return the real package.
Workaround (in metro.config.js, after both wrappers):
const path = require('node:path');
const reactNativeCssDir = `${path.sep}node_modules${path.sep}react-native-css${path.sep}`;
const resolveRequest = config.resolver.resolveRequest;
config.resolver.resolveRequest = (context, moduleName, platform) =>
moduleName === 'react-native' &&
context.originModulePath.includes(reactNativeCssDir)
? context.resolveRequest(context, moduleName, platform)
: resolveRequest(context, moduleName, platform);
Suggested fix: in nativeResolver, resolve react-native from an internal origin with Metro's default context.resolveRequest instead of the parent resolver. react-native-css's components always need the real package.
Reproduction
npx rn-new@next --nativewind, add react-native-worklets, then in metro.config.js:
const { getDefaultConfig } = require('expo/metro-config');
const { withNativewind } = require('nativewind/metro');
const { getBundleModeMetroConfig } = require('react-native-worklets/bundleMode');
let config = getDefaultConfig(__dirname);
config = withNativewind(config);
config = getBundleModeMetroConfig(config);
module.exports = config;
Launch on iOS. The crash happens during module init, before any component renders.
Versions
- nativewind 5.0.0-rc.0
- react-native-css 3.1.0-rc.0
- react-native-worklets 0.13.0 (react-native-reanimated 4.7.1)
- react-native 0.86.3, expo 57.0.27
- tailwindcss 4.3.3
- iOS simulator, Hermes
Possibly related: #455 has the same error text, but a different trigger (styled() around react-native-svg at render time).
- 主要語言
- TypeScript
- 星號
- 166
- 分支
- 45
- 平均合併
- 13 天 14 小時
- 30 天內合併 PR
- 1
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
nativewind/react-native-css 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 78/100
nativewind/react-native-css#545 ·
維護者通常 3 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
nativewind/react-native-css#544 ·
維護者通常 3 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
nativewind/react-native-css#543 ·
維護者通常 3 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
nativewind/react-native-css#540 ·
維護者通常 3 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
nativewind/react-native-css#538 ·
維護者通常 3 天內回覆
查看 nativewind/react-native-css 的全部 Issue
相似的 Issue
-
fix(worker): keep normal prepare waiting states failure-free可能已有人在做 @LichKing-2234 今天認領。 未關閉agent:codex priority:P1
難度 2/5 1-3 小時 新手友好度 72/100
AgoraIO-Extensions/agent-infra#3745 ·
維護者通常 1 天內回覆
-
The five-line work window can drop its oldest line: the per-line byte share ignores the JSON framing可能已有人在做 @Eapp1e 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 84/100
makecindy/cindy#7973 · 1 則留言 ·
維護者通常 1 天內回覆
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難度 1/5 1 小時以內 新手友好度 78/100
lingdojo/kana-dojo#33337 · 1 則留言 · 5 個 reaction ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
code-yeongyu/senpi#4917 · 1 則留言 ·
維護者通常 1 天內回覆