需要未知模块:“未定义”
Posted
技术标签:
【中文标题】需要未知模块:“未定义”【英文标题】:Requiring unknown module: "undefined" 【发布时间】:2021-06-19 14:37:38 【问题描述】:React Native 应用在 Debug 配置中运行良好,但在我为 Release 构建时崩溃,Xcode 提供:
Unhandled JS Exception: Error: Requiring unknown module "undefined"., stack:
h@2:1417
d@2:958
B@660:5322
Ar@91:41759
yl@91:51609
ti@91:78509
ei@91:78437
Za@91:78202
qa@91:75364
qa@(null):(null)
<unknown>@91:26064
<unknown>@189:3806
Ct@91:26011
Pt@91:25946
Oa@91:72858
al@91:47559
al@(null):(null)
<unknown>@660:4257
dispatchEvent@125:5675
<unknown>@138:3390
value@24:896
value@39:3492
<unknown>@39:747
value@39:2538
value@39:719
value@(null):(null)
这是我的依赖项:
"dependencies":
"@react-native-async-storage/async-storage": "^1.15.5",
"@react-native-clipboard/clipboard": "^1.8.1",
"@react-native-community/slider": "^3.0.3",
"@react-navigation/bottom-tabs": "^5.11.10",
"@react-navigation/native": "^5.9.4",
"@react-navigation/stack": "^5.14.4",
"jsdom-jscore-rn": "github:iamcco/jsdom-jscore-rn#master",
"moment": "^2.29.1",
"prop-types": "^15.7.2",
"react": "17.0.1",
"react-native": "0.64.0",
"react-native-circular-progress": "^1.3.7",
"react-native-circular-slider": "^1.0.1",
"react-native-elements": "^3.4.1",
"react-native-gesture-handler": "^1.10.3",
"react-native-haptic-feedback": "^1.11.0",
"react-native-linear-gradient": "^2.5.6",
"react-native-modal": "^11.10.0",
"react-native-notifications": "^3.5.0",
"react-native-reanimated": "^2.1.0",
"react-native-safe-area-context": "^3.2.0",
"react-native-screens": "^3.1.1",
"react-native-snap-carousel": "^3.9.1",
"react-native-splash-screen": "^3.2.0",
"react-native-svg": "^12.1.1",
"react-native-svg-charts": "^5.4.0",
"react-native-svg-transformer": "^0.14.3",
"react-native-vector-icons": "^8.1.0",
"react-navigation": "^4.4.4",
"react-navigation-stack": "^2.10.4",
"rn-circular-slider": "^1.1.0"
我怀疑是 jsdom-jscore-rn 导致了这个问题,因为它具有循环依赖关系。 (登录屏幕重定向到使用此模块的屏幕后崩溃)
还可能值得注意的是,我使用的是通过以下方式生成的离线包:
npx react-native bundle --dev false --entry-file index.js --bundle-output ios/main.jsbundle --platform ios --assets-dest iOS
如何调试此错误或至少了解此错误的来源?有行号我可以看吗?如何在不必完全禁用此模块的情况下解决此问题?
更新:已修复。查看答案。
干净安装节点模块没有帮助,旧线程:Requiring unknown module “undefined” on react-native-maps、Requiring unknown module “undefined” 也没有帮助。
【问题讨论】:
【参考方案1】:更新:我能够修复它。这个问题根本与 node_modules 无关。
真正的问题:
<Image source=require('./assets/image.png') />
当我为 Release 构建时,图像没有被包含在内。通过手动将图像添加到 xcassets (iOS) 并将该行更改为:
<Image source= uri: 'image' />
【讨论】:
以上是关于需要未知模块:“未定义”的主要内容,如果未能解决你的问题,请参考以下文章
Protractor Angular 2 失败:未知错误:未定义角度
Angular AOT Build:内部错误:未知标识符未定义