【问题标题】:Unable to resolve module @react-native-async-storage/async-storage无法解析模块 @react-native-async-storage/async-storage
【发布时间】:2021-06-07 02:23:02
【问题描述】:

将 aws-amplify 添加到项目后出现此错误,是否根据文档完成了 aws-amplify 的设置,然后 pod install 和 react-native run-ios 我也尝试过更改以下错误建议中提到的导入语句,但仍然无法正常工作,提前致谢。

  node_modules/@aws-amplify/core/node_modules
  node_modules
  ../node_modules

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
  11 |  * and limitations under the License.
  12 |  */
> 13 | import AsyncStorage from '@react-native-async-storage/async-storage';
     |                           ^
  14 | var MEMORY_KEY_PREFIX = '@MemoryStorage:';
  15 | var dataMemory = {};
  16 | /** @class */
    at ModuleResolver.resolveDependency (/Users/monk/Projects/Airbnb/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:234:15)
    at DependencyGraph.resolveDependency (/Users/monk/Projects/Airbnb/node_modules/metro/src/node-haste/DependencyGraph.js:413:43)
    at Object.resolve (/Users/monk/Projects/Airbnb/node_modules/metro/src/lib/transformHelpers.js:317:42)
    at resolve (/Users/monk/Projects/Airbnb/node_modules/metro/src/DeltaBundler/traverseDependencies.js:629:33)
    at /Users/monk/Projects/Airbnb/node_modules/metro/src/DeltaBundler/traverseDependencies.js:645:26
    at Array.reduce (<anonymous>)
    at resolveDependencies (/Users/monk/Projects/Airbnb/node_modules/metro/src/DeltaBundler/traverseDependencies.js:644:33)
    at /Users/monk/Projects/Airbnb/node_modules/metro/src/DeltaBundler/traverseDependencies.js:329:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/monk/Projects/Airbnb/node_modules/metro/src/DeltaBundler/traverseDependencies.js:137:24)```

【问题讨论】:

  • 清除缓存重试
  • 我在更新 aws-amplify 后也遇到了这个问题。显式添加依赖项解决了问题,尽管不是 100% 确定这是正确的方法。

标签: react-native aws-amplify


【解决方案1】:

安装 Amplify 库:here

yarn add @react-native-async-storage/async-storage

之后如果有问题尝试清理项目,

rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/haste-* && watchman watch-del-all && yarn cache clean --force && rm -rf ios/build && rm -rf node_modules/
yarn install
rm -rf pods && pod install

【讨论】:

    【解决方案2】:

    我刚刚从模拟器中删除了应用程序并重新安装了它,经过长时间的研究,它终于可以正常工作了!

    【讨论】:

      【解决方案3】:

      我解决了 - 在 package.json 中

      "@react-native-community/async-storage": "https://github.com/react-native-async-storage/async-storage",
      

      【讨论】:

      • 我不建议这样做,因为每次你执行“npm i”时,它都会寻找最新版本,包括那些有重大变化的版本,并将其应用到你的项目中。这可能会引入您可能不会立即看到的重大更改。
      猜你喜欢
      • 1970-01-01
      • 2019-10-08
      • 2017-10-31
      • 2021-02-16
      • 1970-01-01
      • 1970-01-01
      • 2022-08-10
      • 2021-11-13
      • 1970-01-01
      相关资源
      最近更新 更多