Expo SDK41启动报Module "undefined" is missing from the asset registry如何解决
错误根因
从错误栈可直接定位,问题出在App.js中cacheImages方法的资源遍历逻辑:你传入的待预加载静态资源数组中存在undefined值,expo-asset的fromModule方法接收到无效的undefined模块后抛出该错误,和你排查的应用图标无关。
排查修复步骤
- 打开App.js定位到第30行的
cacheImages方法,以及第34行的map遍历逻辑,先打印完整的待预加载资源数组,快速定位其中值为undefined的项 - 校验undefined项对应的资源导入路径:Expo SDK 41对资源路径大小写敏感,需要确认路径大小写、相对层级和实际文件位置完全匹配,大小写不匹配会导致require返回undefined
- 禁止使用动态拼接的require路径:Expo不支持
require(../assets/${imgName}.png)这类动态路径写法,所有require的路径必须为静态字符串,否则无法正确识别资源,返回undefined - 检查资源导入语句是否存在拼写错误,导致资源变量未正确赋值
快速验证方法
暂时注释掉App.js中调用cacheImages预加载资源的逻辑,直接启动应用,如果可以正常启动,即可确认是预加载资源列表的问题,再逐个校验资源路径即可。
完整错误栈参考
Module "undefined" is missing from the asset registry at node_modules\expo-asset\build\Asset.js:53:18 in fromModule at App.js:34:11 in images.map$argument_0 at [native code]:null in map at App.js:30:9 in cacheImages at App.js:46:33 in _loadResourcesAsync at node_modules\expo-app-loading\build\AppLoading.js:17:4 in startLoadingAppResourcesAsync at node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch at node_modules\regenerator-runtime\runtime.js:293:29 in invoke at node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch at node_modules\regenerator-runtime\runtime.js:154:27 in invoke at node_modules\regenerator-runtime\runtime.js:189:16 in PromiseImpl$argument_0 at node_modules\es6-promise\dist\es6-promise.js:463:6 in initializePromise at node_modules\es6-promise\dist\es6-promise.js:875:38 in Promise at node_modules\regenerator-runtime\runtime.js:188:15 in callInvokeWithMethodAndArg at node_modules\regenerator-runtime\runtime.js:211:38 in enqueue at node_modules\regenerator-runtime\runtime.js:238:8 in exports.async at node_modules\expo-app-loading\build\AppLoading.js:17:4 in startLoadingAppResourcesAsync at node_modules\expo-app-loading\build\AppLoading.js:9:8 in componentDidMount at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:15688:12 in commitLifeCycles at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18744:22 in commitLayoutEffects at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:265:4 in invokeGuardedCallbackImpl at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:476:2 in invokeGuardedCallback at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18483:29 in commitRootImpl at [native code]:null in commitRootImpl at node_modules\scheduler\cjs\scheduler.development.js:653:23 in unstable_runWithPriority at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18317:17 in commitRoot at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:17697:12 in performSyncWorkOnRoot at [native code]:null in performSyncWorkOnRoot at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5321:31 in runWithPriority$argument_1 at node_modules\scheduler\cjs\scheduler.development.js:653:23 in unstable_runWithPriority at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5316:21 in flushSyncCallbackQueueImpl at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5304:28 in flushSyncCallbackQueue at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:17125:30 in scheduleUpdateOnFiber at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:20527:14 in updateContainer at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:21068:17 in render at node_modules\react-native\Libraries\ReactNative\renderApplication.js:54:4 in renderApplication at node_modules\react-native\Libraries\ReactNative\AppRegistry.js:117:25 in runnables.appKey.run at node_modules\react-native\Libraries\ReactNative\AppRegistry.js:213:4 in runApplication at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in __callFunction at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in __guard$argument_0 at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 in callFunctionReturnFlushedQueue at [native code]:null in callFunctionReturnFlushedQueue
内容的提问来源于stack exchange,提问作者Sephora Perez
相关产品推荐
相关产品推荐

