`无法解析模块@react-native-community/async-storage` 破坏了我的 React Native 环境 [英] `unable to resolve module @react-native-community/async-storage` broke down my React Native environment

查看:32
本文介绍了`无法解析模块@react-native-community/async-storage` 破坏了我的 React Native 环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上遇到了与这里相同的问题.

I'm basically having the issue same as here.

https://github.com/firebase/firebase-js-sdk/问题/1899

由于 AsyncStorage 已弃用,我尝试按照 官方文档

Since AsyncStorage is deprecated, I tried to install @react-native-community/async-storage following the official documentation

但它完全失败了,因为我收到了上面的错误.因此,我想回滚到我以前的工作版本,除了我所做的没有工作.

But it failed completely as I got the error above. Thus I wanted to roll back to my previous working version except none of what I did worked.

  1. 错误屏幕上建议的 4 个命令
  2. 使用yarn remove
  3. 撤销yarn add
  4. 我也做了 npm install @react-native-community/async-storage,没有用.3.5 所以我做了 npm uninstall @react-native-community/async-storage 它被删除了,但回滚不起作用.
  5. 重新安装react-native-cli
  6. 重新创建一个完全从头开始的新项目,但它仍然给出同样的错误.
  1. 4 commands suggested on the error screen
  2. undoing yarn add with yarn remove
  3. I also did npm install @react-native-community/async-storage, did not work. 3.5 so I did npm uninstall @react-native-community/async-storage It was removed, but roll-back did not work.
  4. Re-installing the react-native-cli
  5. Re-creating a completely new project from scratch, but it is still giving the same error.

我找不到解决方案.请帮忙.

I could not find a solution for this. Please help.

推荐答案

如果是在 iOS 上,您可能忘记执行 pod install.

If it's on iOS you probably forgot to do pod install.

将其粘贴到 ios/Podfile 中:

  pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'

然后只做 cd ios &&pod安装

编辑.

我从头开始创建一个项目,这是我在 iOS 和 Android 上运行 asyncStorage 的步骤:

I createad a project from scratch, this are the steps i did to make asyncStorage run on iOS and Android:

1) react-native init AsyncTest

2) npm i @react-native-community/async-storage

(在此步骤中尝试使用 asyncStorage 显示错误,但适用于 Android)

(trying to use asyncStorage during this step shows error, but works on Android)

3) 将这个 pod 粘贴到 Podfile 中:

3) Pasted inside Podfile this pod:

  pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'

4) 从终端,​​假设您在项目文件夹中执行 cd iospod install

4) From terminal, assuming you are in the project folder do cd ios and pod install

5) 项目在 iOS 上成功运行并运行.

5) Project run succesfully on iOS and works.

react-native 版本是 0.60.4

react-native version was 0.60.4

这是项目测试 App.js 用于测试的方式:

This is how the project test App.js was for the test:

import React from 'react';
import { View } from 'react-native';
import AsyncStorageTest from './AsyncStorageTest'
const App = () => {
  return (
    <View>
      <AsyncStorageTest />
    </View>
  );
};

export default App

AsyncStorageTest 是:

And AsyncStorageTest is:

import React, { Component } from 'react'
import { View, Text, Button } from 'react-native'
import AsyncStorage from '@react-native-community/async-storage';

export class AsyncStorageTest extends Component {
    constructor(props) {
        super(props)
        this.state = {
            storedData: "myValue"
        }
    }


storeData = async () => {
    console.log("inside storeData")
    try {
        await AsyncStorage.setItem('Test', 'TestValue')
    } catch (e) {
        console.log(e)
    }
}

getData = async () => {
    console.log("inside getData")
    try {
        const value = await AsyncStorage.getItem('Test')
        this.setState({ storedData: value })

    } catch (e) {
        // error reading value
    }
}

render() {
    return (
        <View style={{ marginTop: 40 }}>
            <Text> {this.state.storedData}</Text>
            <Button title={"storeData"} onPress={this.storeData}></Button>
            <Button title={"getData"} onPress={this.getData}></Button>
        </View>
    )
}
}


export default AsyncStorageTest

经过测试和工作,看看您是否遗漏了什么.

Tested and worked, see if you missed something.

确保 @react-native-community/async-storage 已与您的项目取消链接.

Make sure the that @react-native-community/async-storage is unlinked from your project.

这篇关于`无法解析模块@react-native-community/async-storage` 破坏了我的 React Native 环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆