Is it possible to bring in typescript types from a Lambda Layer?

While trying to leverage TypeScript for building Lambda functions, I encountered a roadblock when using a Lambda Layer also written in TypeScript.

The issue arises because TypeScript does not recognize the /opt/nodejs/... import path for my Layer (as it normally would in SAM or AWS). Consequently, I am unable to import the types defined in the Layer into my Lambda function.

I attempted to npm link the layer, but ran into difficulties as the import is a local path '/opt/nodejs...' rather than just a module name.

Layer:

export interface SomeType {
  someField: string
}

Lambda:

import { SomeType } from '/opt/nodejs/myLayer' // this does not work

My attempts result in the error:

Cannot find module '/opt/nodejs/myLayer'.ts(2307)
. To proceed, I have to suppress this with
// @ts-ignore can be ignored as this is a Lambda layer
, but this means I lose access to the TypeScript types provided by the layer.

Answer №1

After some investigation, I believe I have found the solution to this issue. By including the path /opt/nodejs... as a path mapping in tsconfig.json, like so:

{
    "paths": {
      "/opt/nodejs/myLayer": ["../../layers/myLayer/src/some-layer-module"]
    }
}

Now, I am able to import TypeScript types from the Layer without changing the import path, ensuring that it still functions properly in AWS/SAM environment.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with Angular project: View not being updated when using behaviorSubjects

Within my Angular project, I am retrieving data from an API using a service and storing the data within a BehaviorSubject as shown below private categorySubject = new BehaviorSubject<number | null>(null); apiBehavior = new ReplaySubject<ApiRes ...

Is there a way to make an angular component reuse itself within its own code?

I am dealing with a parent and child component scenario where I need to pass data from the parent component to the child component. The aim is to display parentData.name in the child component when parentData.isFolder===false, and if parentData.isFolder=== ...

How can I prevent scrolling in Angular's cdk-virtual-scroll feature?

Is there a way to use Angular's cdk-virtual-scroll to prevent the scrollbar from moving by default? I have done extensive research but have not been able to find a solution. ...

Creating dynamic Angular child routes with variable initial segment

Recently, I've been working on a new project to set up a blogging system. The next step in my plan is to focus on the admin section, specifically editing posts. My idea for organizing the routes is as follows: /blog - Home page /blog/:slug - Access ...

Troubleshooting: Angular add/edit form issue with retrieving data from a Span element within an ngFor loop

I am currently working on an add/edit screen that requires submitting a list, among other data. The user will need to check 2-3 checkboxes for this specific data, and the saved record will have multiple options mapped. Here is what the HTML looks like: &l ...

Why does TypeScript not generate an error if props are not passed to a functional component?

How does TypeScript handle not passing down props to a functional component without throwing an error? Consider the following code snippet: interface Props{ id: string; className?: string; } export const Buttons: React.FC<Props> = () => { r ...

Assets in production encountering a 404 error - distribution glitch

Once the base href URL is added to index.html <base href="."> I proceed to run production mode using "ng build --prod" After encountering a 404 Error, I moved the dist folder into the xampp htdocs folder and included an error image https://i.ssta ...

How to navigate to a custom error page in Angular 2

I have set up a custom error handler and in that, I want to redirect to a custom error page displaying the message "sorry, an error occurred......". To achieve this, I added a route in my app-routing.module.ts file as follows: import { NgModule } from &a ...

How to pass an array as parameters in an Angular HTTP GET request to an API

Hey there! I'm relatively new to Angular and I've hit a roadblock. I need to send an array as parameters to a backend API, which specifically expects an array of strings. const params = new HttpParams(); const depKey = ['deploymentInprogre ...

Data not showing up in *ngFor loop

component.ts file posts= []; constructor( private http:HttpClient) { http.get('https://jsonplaceholder.typicode.com/posts') .subscribe(response=>{ this.posts.push(response) console.log(this.posts) }); } Within the ...

When implementing a TypeScript interface, there is no method parameter checking performed

interface IConverter { convert(value: number): string } class Converter implements IConverter { convert(): string { // no error? return ''; } } const v1: IConverter = new Converter(); const v2: Converter = new Converter(); ...

Ways to access UserProfile in a different Dialogio

For the implementation of a chatbot, I am utilizing Microsoft's Bot Builder framework. However, upon implementing an alternative path to the dialog flow, I noticed that the user's Profile references are getting lost. Here is the code snippet fr ...

Using Typescript to send dates through an Ajax POST request

I am currently working on developing an MVC web application in c# and implementing Typescript for the frontend. I have a controller method that receives a HttpPost request with a data model, which is automatically generated as a Typescript class using type ...

Error 404 returned when making an Angular HTTP POST request to a Heroku application

I am currently encountering an issue with my Angular project, where I am trying to send a POST Request to an Express Server hosted on Heroku in order to send out an email. However, every time I send the POST request to the server, I receive a 404 error. M ...

The 'src' properties in nextjs/image are of different types and therefore cannot be used interchangeably

I'm currently using React Dropzone to upload multiple images in my basic application. To display the types of images that are being dropped, I created a separate component with TypeScript. However, Next.js is throwing an error when it comes to the ima ...

Tips for dismissing loader in Ionic 4

I'm struggling to programmatically dismiss the loader. I've developed two separate methods - one for displaying the loader and another for dismissing it. These methods are called accordingly when needed. async showLoader() { this.loader = a ...

Implementing a defined string constant with a specific type in Typescript

Consider the following predefined object: const obj = { ONE: 'ONE', TWO: 'TWO' }; If I attempt to assign the constant obj.ONE to a new type like this: type TOne = obj.ONE An error message is displayed stating: Cannot find names ...

Is there a way to access service data within an Angular interceptor?

I'm trying to include my authentication token in the request header within my auth.interceptor.ts. The value of the authentication token is stored in auth.service.ts. Below is the code for auth.interceptor.ts @Injectable() export class AuthIntercepto ...

Plugin for managing network connectivity in Ionic framework

In order to check if internet and id connection are available, I need to make a server request. I have implemented the Ionic Native Network Plugin following their official documentation. Here is my code snippet: import { Component } from '@angular/c ...

What was the reason for the delay in updating the local state within the ToggleButtonsGroup MUI component caused by the onChange handler?

I've encountered an issue with the ToggleButtonGroup component from the material-ui library, specifically in the onChange handler. I started with a more complex code and simplified it step by step to arrive at this code snippet. However, I'm puzz ...