首页 > 解决方案 > React Native 0.59 -> 0.60 - 无法解析模块“NativeModules”

问题描述

我想确保我的原生库可以在 0.6x React Native 上运行。我有一个在 0.59.x 上运行的库版本,但是当我在 0.6x 上运行它时,我得到以下 json 响应(连同服务器 500):

Body:
    {"originModulePath":"screens/custom-action-screen.js","targetModuleName":"NativeModules","message":"Unable to resolve module `NativeModules` from `screens/custom-action-screen.js`: NativeModules could not be found within the project.\n\nIf you are sure the module exists, try these steps:\n 1. Clear watchman watches: watchman watch-del-all\n 2. Delete node_modules: rm -rf node_modules and run yarn install\n 3. Reset Metro's cache: yarn start --reset-cache\n 4. Remove the cache: rm -rf /tmp/metro-*","errors":[{"description":"Unable to resolve module `NativeModules` from `screens/custom-action-screen.js`: NativeModules could not be found within the project.\n\nIf you are sure the module exists, try these steps:\n 1. Clear watchman watches: watchman watch-del-all\n 2. Delete node_modules: rm -rf node_modules and run yarn install\n 3. Reset Metro's cache: yarn start --reset-cache\n 4. Remove the cache: rm -rf /tmp/metro-*"}],"name":"Error","stack":"Error: Unable to resolve module `NativeModules` from `screens/custom-action-screen.js`: NativeModules could not be found within the project.\n\nIf you are sure the module exists, try these steps:\n 1. Clear watchman watches: watchman watch-del-all\n 2. Delete node_modules: rm -rf node_modules and run yarn install\n 3. Reset Metro's cache: yarn start --reset-cache\n 4. Remove the cache: rm -rf /tmp/metro-*\n    at ModuleResolver.resolveDependency (/Users/krzysztofkubicki/Workspace/PublicRelease/React-Native-Dev/SampleApp/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:186:15)\n    at ResolutionRequest.resolveDependency (/Users/krzysztofkubicki/Workspace/PublicRelease/React-Native-Dev/SampleApp/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:52:18)\n    at DependencyGraph.resolveDependency (/Users/krzysztofkubicki/Workspace/PublicRelease/React-Native-Dev/SampleApp/node_modules/metro/src/node-haste/DependencyGraph.js:282:16)\n    at Object.resolve (/Users/krzysztofkubicki/Workspace/PublicRelease/React-Native-Dev/SampleApp/node_modules/metro/src/lib/transformHelpers.js:267:42)\n    at /Users/krzysztofkubicki/Workspace/PublicRelease/React-Native-Dev/SampleApp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:426:31\n    at Array.map (<anonymous>)\n    at resolveDependencies (/Users/krzysztofkubicki/Workspace/PublicRelease/React-Native-Dev/SampleApp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:423:18)\n    at /Users/krzysztofkubicki/Workspace/PublicRelease/React-Native-Dev/SampleApp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:275:33\n    at Generator.next (<anonymous>)\n    at asyncGeneratorStep (/Users/krzysztofkubicki/Workspace/PublicRelease/React-Native-Dev/SampleApp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:87:24)"}

所以我的问题是:在以前的版本中怎么可能NativeModules是“可见的”?我所做的只是升级 react 原生版本并保留所有代码。

它仍然适用于 0.59。

标签: react-nativereact-native-android

解决方案


推荐阅读