1

Problem:

Whilst developing my Code Pipeline, I am experiencing a new error I did not receive with cdk deploy --all in the CLI. All stacks deploy successfully.

Code Build Error Message:

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

enter image description here

Lambda Function Import Statements:

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

Lambda Function Package.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 Function CDK Definition:

    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"] },
    });
fedonev
  • 20,327
  • 2
  • 25
  • 34
Luke
  • 761
  • 1
  • 18
  • Does this answer your question? [AWS CodeBuild tsc error TS2307: Cannot find module](https://stackoverflow.com/questions/66590492/aws-codebuild-tsc-error-ts2307-cannot-find-module) – fedonev Jan 02 '23 at 10:29
  • @fedonev, I believe that solution is "ensure my npm version is the same as the Code Build version. For that, I put `installCommands: ["npm i -g npm@latest"]` in my `new ShellStep`. I still have the issue. – Luke Jan 02 '23 at 10:46
  • Have you verified that you have installed the packages before the `cdk synth` command runs? – fedonev Jan 02 '23 at 12:15
  • @fedonev, my thoughts are the node_modules are not installing for each Lambda function or layer. I'm looking at NodejsFunction bundling options now. How would you recommended verifying whether they're installed? – Luke Jan 02 '23 at 12:24
  • I understand your project has multiple `package.json`. In your pipeline `ShellStep` commands, make sure you are running `npm ci` for each one to install the dependencies. – fedonev Jan 02 '23 at 12:50
  • I added this to the commands ` "cd src/lambda-handlers/api-gateway-entry-points/entryPointMagentoCredits", "npm ci", "cd ../../../../",` and it fixed this specific issue. Thank you! Onto the next Code Build Issue. Would you like to write the answer? – Luke Jan 02 '23 at 13:15
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/250790/discussion-between-luke-and-fedonev). – Luke Jan 02 '23 at 13:26

1 Answers1

1

Porting the solution from the comments for posterity:

  1. Do you have mismatched npm CLI versions? AWS CodeBuild tsc error TS2307: Cannot find module.
  2. I understand your project has multiple package.json. In your pipeline ShellStep commands, make sure you are running npm ci for each one to install the dependencies.
fedonev
  • 20,327
  • 2
  • 25
  • 34