0

I'm having an issue with my typescript serverless CDK lambda dependencies. Simply running npm install and routing to the file where I'm importing the @ericblade/quagga2 module, I can command click and route to the module.

However, when running the command sam local invoke --event s3-event.json I get an error that the module could not be found. ( other modules like aws-sdk were found )

I'm thinking this is a typescript problem, but I'm not sure how to fix it. I'm unfamiliar with any custom d.ts file hack that would solve this problem.

import statement : const Quagga = require('@ericblade/quagga2').default

tsconfig.json:

{
  "compilerOptions": {
    "target": "ES2018",
    "module": "commonjs",
    "esModuleInterop": true,
    "lib": [
      "es2018",
      "dom"
    ],
    "declaration": true,
    "moduleResolution": "node",
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": false,
    "inlineSourceMap": true,
    "inlineSources": true,
    "experimentalDecorators": true,
    "strictPropertyInitialization": false,
    "typeRoots": [
      "./node_modules/@types"
    ]
  },
  "exclude": [
    "cdk.out"
  ]
}

I've tried messing around with different configurations in the tsconfig, but I'm not really sure what I'm doing.

cWerning
  • 583
  • 1
  • 5
  • 15

1 Answers1

0

This problem was because I didn't have a package.json at the lambda level directory for lambda dependencies. The library aws-sdk was working at not throwing a module not found error because it is baked into the SAM testing image.

cWerning
  • 583
  • 1
  • 5
  • 15