【问题标题】:AWS CDK Code Pipeline Development - Typescript Error TS2307AWS CDK 代码管道开发 - Typescript 错误 TS2307
【发布时间】:2023-01-02 21:46:51
【问题描述】:

问题:

在开发我的代码管道时,我遇到了一个新错误,我没有在 CLI 中收到 cdk deploy --all。所有堆栈部署成功。

代码构建错误消息:

    src/lambda-handlers/queue-consumers/intoMagentoQueueConsumer/index.ts(3,75): error TS2307: Cannot find module '@aws-sdk/client-sfn' or its corresponding type declarations.

Lambda 函数导入语句:

    import { SFNClient, SendTaskSuccessCommand, SendTaskFailureCommand } from "@aws-sdk/client-sfn";

Lambda 函数包.json:

    {
      "name": "intomagentoqueueconsumer",
      "module": "commonjs",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "keywords": [],
      "author": "",
      "license": "ISC",
      "dependencies": {
        "@aws-sdk/client-sfn": "^3.226.0",
        "axios": "^1.2.1",
        "axios-retry": "^3.3.1"
      }
    }

Lambda 函数 CDK 定义:

    this.intoMagentoQueueConsumer = new NodejsFunction(this, `intoMagentoQueueConsumer`, {
      runtime: Runtime.NODEJS_16_X,
      handler: "handler",
      depsLockFilePath: join(__dirname, "../../src/lambda-handlers/queue-consumers/intoMagentoQueueConsumer/package-lock.json"),
      entry: join(__dirname, "../../src/lambda-handlers/queue-consumers/intoMagentoQueueConsumer/index.ts"),
      bundling: { minify: false, nodeModules: ["@aws-sdk/client-sfn", "axios", "axios-retry"], externalModules: ["aws-sdk", "crypto-js"] },
    });

【问题讨论】:

  • 这回答了你的问题了吗? AWS CodeBuild tsc error TS2307: Cannot find module
  • @fedonev,我认为解决方案是“确保我的 npm 版本与代码构建版本相同。为此,我将 installCommands: ["npm i -g npm@latest"] 放在我的 new ShellStep 中。我仍然有问题。
  • cdk synth 命令运行之前,您是否已确认您已经安装了这些软件包?
  • @fedonev,我的想法是没有为每个 Lambda 函数或层安装 node_modules。我现在正在查看 NodejsFunction 捆绑选项。您建议如何验证它们是否已安装?
  • 我了解到您的项目有多个package.json。在您的管道 ShellStep 命令中,确保您正在为每个命令运行 npm ci 以安装依赖项。

标签: aws-cdk aws-codebuild


【解决方案1】:

为后代从 cmets 移植解决方案:

  1. 是否有不匹配的npm CLI 版本? AWS CodeBuild tsc error TS2307: Cannot find module
  2. 我了解到您的项目有多个package.json。在您的管道 ShellStep 命令中,确保您正在为每个命令运行 npm ci 以安装依赖项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    • 1970-01-01
    相关资源
    最近更新 更多