使用aws放大react native和expo上的aws来获取错误“不支持节点”

时间:2019-12-05 20:21:32

标签: amazon-web-services react-native expo aws-amplify aws-appsync

AWS在re:invent 2019上引入了AmplifyDataStore。Datastore是一个持久的设备上存储存储库,供开发人员编写,读取和观察数据更改。

根据该公告,Amplify DataStore允许开发人员编写利用分布式数据的应用程序,而无需为离线或在线场景编写其他代码。 Amplify DataStore可以用作Web和移动应用程序中的独立本地数据存储,而无需连接到云,也不需要拥有AWS账户。底层是连接到应用程序同步graphQl API的数据存储。令人敬畏的功能是易于使用和脱机功能。另请参见公告https://aws.amazon.com/de/blogs/aws/amplify-datastore-simplify-development-of-offline-apps-with-graphql/或文档https://aws-amplify.github.io/docs/js/datastore

但是,放大支持流行的Web框架,例如Angular,React和Vue。它还支持使用React Native,iOS的Swift或Android的Java开发的移动应用程序。

发布公告后,我被激励使用基于React Native应用和博览会的功能。

但是使用aws放大react native和expo上的aws时会出现错误“不支持节点”。

[Unhandled promise rejection: Error: Node is not supported]
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:63717:20 in getDefaultAdapter
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:63730:47 in Storage
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:64010:31 in ExclusiveStorage
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:61426:81 in <unknown>
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:60761:23 in step
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:60663:9 in <unknown>
- node_modules/promise/setimmediate/core.js:45:7 in tryCallTwo
- node_modules/promise/setimmediate/core.js:200:23 in doResolve
- node_modules/promise/setimmediate/core.js:66:12 in Promise
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:60642:34 in <unknown>
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:61204:17 in <unknown>
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:60761:23 in step
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:60663:9 in <unknown>
- node_modules/promise/setimmediate/core.js:45:7 in tryCallTwo
- node_modules/promise/setimmediate/core.js:200:23 in doResolve
- node_modules/promise/setimmediate/core.js:66:12 in Promise
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:60642:34 in <unknown>
* App.js:43:40 in loadData$

导入的数据存储区和模型:

import { DataStore } from "@aws-amplify/datastore";
import { Post } from "./src/models";
import amplify from './aws-exports';
Amplify.configure(amplify);

并使用数据存储区API创建加载数据:

  async loadData() {
    await DataStore.save(
      new Post({
        name: `My First Post`
      })
    ).catch(err => {
      console.error(err)
    });

    const posts = await DataStore.query(Post);
    console.log(posts)
  }

依赖项:

    "dependencies": {
        "@aws-amplify/api": "^2.1.1",
        "@aws-amplify/core": "^2.2.0",
        "@aws-amplify/datastore": "^1.0.2",
        "@aws-amplify/pubsub": "^2.1.1",
        "aws-amplify": "1.2.2",
        "expo": "^35.0.0",
        "react": "16.8.3",
        "react-dom": "16.8.3",
        "react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
        "react-native-web": "^0.11.7"
    }

2 个答案:

答案 0 :(得分:3)

该库目前尚未准备好用于React Native 参考:https://github.com/aws-amplify/amplify-js/issues/4527

答案 1 :(得分:1)

React Native现在支持

DataStore。您可以在此处找到安装说明:https://aws-amplify.github.io/docs/js/datastore#for-react-native