Serverless-webpack: The Lambda layer is not working with Typescript.

Created on 15 Feb 2020  路  7Comments  路  Source: serverless-heaven/serverless-webpack

This is a (Bug Report / Feature Proposal)

Bug Report

Description

I'm using AWS as a cloud provider. I created a serverless project with the NodeJS Typescript template to use Lambda Layers. Service only contains the layer details in the serverless.yml file. When I'm trying you to package it, it's throwing an error called entry can't be non-empty value. So I checked the serverless-webpack npm module. It seems it's only generating entries for the Lambda functions not for the layers. I modified the validation and generated the entries for layers as well in the npm library and pointed the entry as database/nodejs/node-modules/database/index.ts in the tsconfig.json file Then it's successfully packaging the layer.

For bug reports:
Ts files are not getting compiled with the given folder structure. ASW have their folder structure to create lambda layer https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html. I followed the same structure
My folder structure: database/nodejs/node-modules/database/index.ts
(index.ts contains the typescript code).

The generated folder structure under .serverless folder is database.zip which contains (database/nodejs/node-modules/database/index.ts). This code has not complied. Seems it's just zipping the folder. If I use the mongoose npm library then the compiler is not resolving the file and it's throwing an error saying module is not resolved. But the file is there. under the node module.

The expected folder structure is database.zip which contains (database/nodejs/node-modules/database/index.js). index.js is a complied version of index.ts

For feature proposals:

Similar or dependent issue(s):

Additional Data

  • Serverless-Webpack Version you're using: 1.63.0
  • Webpack version you're using:
  • Serverless Framework Version you're using:
  • Operating System: win32
  • Stack Trace (if available):

Most helpful comment

I've seen workarounds but is there any update on this issue officially?

All 7 comments

This is my folder Stucture.
folder stuction

This is the ts file
index

This is the
tsconfig

I am facing the similar issue while using AWS Lambda layers with TypeScript

I've seen workarounds but is there any update on this issue officially?

Im facing the same issue. Is there any workaround?

Same issue here.

Is there any chance to have a repo with minimal information to reproduce the issue?

Is there any chance to have a repo with minimal information to reproduce the issue?

I created a small repo to reproduce it: https://github.com/chriszirkel/serverless-webpack-layers

If you npx sls package it, the resulting testLayer.zip will contain the original index.ts Typescript file.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aaronjensen picture aaronjensen  路  5Comments

bitttttten picture bitttttten  路  4Comments

bebbi picture bebbi  路  3Comments

hassankhan picture hassankhan  路  3Comments

jonni-larjomaa picture jonni-larjomaa  路  3Comments