You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Amplify Gen2部署Lambda时package.json的overrides配置无效

Amplify Gen2部署Lambda连接AppSync时遭遇graphql重复依赖报错

我正尝试用Amplify Gen2部署Lambda函数,实现通过AppSync将Amazon Connect通话记录存入DynamoDB。Lambda函数代码如下:

import { Handler, ConnectContactFlowEvent } from "aws-lambda";
import { gql } from "graphql-tag";
import AWSAppSyncClient from 'aws-appsync';

const client = new AWSAppSyncClient({
    url: "xxx",
    region: 'xxx',
    auth: {
      type: "API_KEY",
      apiKey: "xxx",
    },
    disableOffline: true,
  });

export const handler: Handler = async (event, context) => {

  await createContactHistory(event);

  return { result: "success" };
};

async function createContactHistory(event: ConnectContactFlowEvent) {
  const contactHistory = {
    contactId: event.Details.ContactData.ContactId,
    inboundPhoneNumber: event.Details.ContactData.CustomerEndpoint.Address
  };

  return await client.mutate({
    variables: contactHistory,
    mutation: CreateContactHistory
  })
}

const CreateContactHistory = gql`
  mutation MyMutation($contactId: String!, $inboundPhoneNumber: AWSPhone!) {
    createContactHistory(
      input: { contactId: $contactId, inboundPhoneNumber: $inboundPhoneNumber }
    ) {
      contactId
      createdAt
      inboundPhoneNumber
      updatedAt
    }
  }
`;

但部署后的Lambda函数index.mjs包含大量非手写代码,且出现以下报错:

确保node_modules目录中只有一个"graphql"实例。如果其他依赖模块依赖不同版本的"graphql",请使用"resolutions"确保只安装一个版本。

不能同时使用重复的"graphql"模块,因为不同版本可能有不同的功能和行为。一个版本的数据用于另一个版本的函数可能会产生混乱和虚假的结果。

我按照指引在package.json中配置overrides指定graphql版本为15.9.0,构建和npm install操作成功,但问题仍未解决。尝试使用yarn install及resolutions配置,情况也无改善。当前package.json内容如下:

{
  "name": "amplify-vite-react-template",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite && npx ampx sandbox",
    "build": "tsc && vite build",
    "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
    "preview": "vite preview"
  },
  "dependencies": {
    "@apollo/client": "^3.11.10", 
    "@aws-amplify/data-schema": "^1.5.1",
    "@aws-amplify/ui-react": "^6.2.0",
    "@emotion/react": "^11.13.5",
    "@emotion/styled": "^11.13.5",
    "@mui/material": "^6.1.8",
    "@mui/x-data-grid": "^7.22.3",
    "@types/google-libphonenumber": "^7.4.30",
    "aws-amplify": "^6.9.0",
    "aws-appsync": "^4.1.10",
    "google-libphonenumber": "^3.2.38",
    "graphql-tag": "^2.12.6",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "overrides": {
    "graphql": "15.9.0"
  },
  "devDependencies": {
    "@aws-amplify/backend": "^1.1.1",
    "@aws-amplify/backend-cli": "^1.2.4",
    "@types/react": "^18.2.66",
    "@types/react-dom": "^18.2.22",
    "@typescript-eslint/eslint-plugin": "^7.2.0",
    "@typescript-eslint/parser": "^7.2.0",
    "@vitejs/plugin-react": "^4.2.1",
    "aws-cdk": "^2.138.0",
    "aws-cdk-lib": "^2.138.0",
    "constructs": "^10.3.0",
    "esbuild": "^0.20.2",
    "eslint": "^8.57.0",
    "eslint-plugin-react-hooks": "^4.6.0",
    "eslint-plugin-react-refresh": "^0.4.6",
    "tsx": "^4.7.2",
    "typescript": "^5.4.5",
    "vite": "^5.2.0"
  }
}

内容的提问来源于stack exchange,提问作者ky_iwanami

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 02:35:13