question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to resolve path to module 'aws-lambda' import/no-unresolved

See original GitHub issue

Hello, I have the following code:

import type { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
import { createLogger, Logger } from '../util/logger';

/**
 * Lambda Handler
 *
 * @param {APIGatewayProxyEvent} event
 * @param {Context} context
 * @returns {Promise<APIGatewayProxyResult>}
 */
export const handler = async (event: APIGatewayProxyEvent, context: Context): Promise<APIGatewayProxyResult> => {
  const logger: Logger = createLogger(event, context);
  const queryParams = (event.queryStringParameters ||
    {}) as Record<string, string>;

  logger.info(JSON.stringify({ queryParams }));

  return Promise.resolve({
    statusCode: 200,
    body: JSON.stringify({ queryParams }),
  });
};

I have added

  "typeRoots": [
    "./node_modules/@types"
  ],

to the tsconfig.json and disabled it in my .projenrc.js disableTsconfig: true,

when running npm run build i get the error:

 Unable to resolve path to module 'aws-lambda'  import/no-unresolved

this is my .projenrc.js file:

const { AwsCdkTypeScriptApp } = require('projen');

const project = new AwsCdkTypeScriptApp({
  cdkVersion: '1.73.0',
  defaultReleaseBranch: 'main',
  jsiiFqn: 'projen.AwsCdkTypeScriptApp',
  name: 'mgm-cerebro',
  cdkDependencies: [
    '@aws-cdk/core',
    '@aws-cdk/aws-apigateway',
    '@aws-cdk/aws-codepipeline',
    '@aws-cdk/aws-codepipeline-actions',
    '@aws-cdk/pipelines',
    '@aws-cdk/aws-lambda',
  ],
  /* AwsCdkTypeScriptAppOptions */
  appEntrypoint: '../bin/main.ts', /* The CDK app's entrypoint (relative to the source directory, which is "src" by default). */
  context: {
    '@aws-cdk/core:enableStackNameDuplicates': 'true',
    'aws-cdk:enableDiffNoFail': 'true',
    '@aws-cdk/core:newStyleStackSynthesis': 'true',
    '@aws-cdk/core:stackRelativeExports': 'true',
  }, /* Additional context to include in `cdk.json`. */

  /* NodePackageOptions */
  // allowLibraryDependencies: true,                                           /* Allow the project to include `peerDependencies` and `bundledDependencies`. */
  deps: [
    '@types/aws-lambda',
    'source-map-support',
  ], /* Runtime dependencies of this module. */

  /* TypeScriptProjectOptions */
  disableTsconfig: true, /* Do not generate a `tsconfig.json` file (used by jsii projects since tsconfig.json is generated by the jsii compiler). */

});

project.synth();
npx cdk --version
1.91.0 (build 0f728ce)

any advice is much appricated

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
hoegertncommented, Jul 18, 2021

You do not need to import the aws-lambda at all in your source file.

You can use AWSLambda.APIGatewayProxyEvent as the type definition provides a global namespace.

Import is broken as the type definition does not match the package aws-lambda which does sth different so you do not want to import it.

0reactions
github-actions[bot]commented, Sep 25, 2021

Closing this issue as it hasn’t seen activity for a while. Please add a comment @mentioning a maintainer to reopen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript/ESLint error: Unable to resolve path to module 'aws ...
This seems to be the relevant issue: github.com/import-js/eslint-plugin-import/issues/1485 Still, I don't understand why @types/aws-lambda ...
Read more >
Unable to resolve path to module 'aws-lambda' import/no ...
I am trying to use the types/aws-lambda definitions in a serverless framework project. ESLint keeps throwing an error at this typing: error ...
Read more >
Resolve "Unable to import module" errors from Python ... - AWS
I receive an "Unable to import module" error when I try to run my AWS Lambda code in Python. How do I resolve...
Read more >
eslint-import-resolver-typescript - Bountysource
For example installing @types/aws-lambda and then using something like ... error Unable to resolve path to module 'esri/arcgis/Portal' import/no-unresolved.
Read more >
unable to resolve path to module eslint - Code Grepper
SM*/ /*Add the following to your eslintrc file*/ { "settings": { "import/resolver": { "node": { "extensions": [".js", ".jsx", ".ts", ".tsx"] } } },...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found