首页 > 解决方案 > AWS Amplify Amplify.configure(awsconfig) 错误

问题描述

我在 NextJs 应用程序中使用了放大 cli。我觉得也许我配置了一些错误我在尝试查询数据时收到此错误:

[警告] 32:17.454 DataStore - 数据不会同步。未配置 GraphQL 端点。你忘记了Amplify.configure(awsconfig)吗?

但我确实有一个 aws-exports.js 文件。但我确实看到它是 awsmobile ,我不确定我可能做错了什么。

aws 导出文件:

const awsmobile = {
  aws_project_region: 'us-east-2',
  aws_appsync_graphqlEndpoint:
    private,
  aws_appsync_region: 'us-east-2',
  aws_appsync_authenticationType: 'API_KEY',
  aws_appsync_apiKey:private,
}

标签: reactjsnext.jsdatastoreamplify

解决方案


正如警告所暗示的,您可能需要检查是否Amplify.configure(awsconfig)调用了在项目中设置库。

例如,这是官方文档中给出的示例。

// pages/index.js
import { AmplifyAuthenticator } from "@aws-amplify/ui-react";
import { Amplify, API, Auth, withSSRContext } from "aws-amplify";
import Head from "next/head";
import awsExports from "../src/aws-exports";
import { createPost } from "../src/graphql/mutations";
import { listPosts } from "../src/graphql/queries";
import styles from "../styles/Home.module.css";

Amplify.configure({ ...awsExports, ssr: true });

在您的情况下,您可以awsmobile从应用程序的入口点导入aws-exports.js和调用Amplify.configure({...awsmobile, ssr: true});


推荐阅读