serverless-webpack icon indicating copy to clipboard operation
serverless-webpack copied to clipboard

The Lambda layer is not working with Typescript.

Open AndrewJR350 opened this issue 4 years ago • 12 comments

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):

AndrewJR350 avatar Feb 15 '20 06:02 AndrewJR350

This is my folder Stucture. folder stuction

This is the ts file index

This is the tsconfig

AndrewJR350 avatar Feb 15 '20 06:02 AndrewJR350

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

itrathnasekara avatar Feb 17 '20 10:02 itrathnasekara

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

iam-yan avatar Aug 08 '20 07:08 iam-yan

Im facing the same issue. Is there any workaround?

eliezerreis avatar Oct 02 '20 17:10 eliezerreis

Same issue here.

zirkelc avatar Jun 21 '21 12:06 zirkelc

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

j0k3r avatar Jun 21 '21 12:06 j0k3r

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.

zirkelc avatar Jun 23 '21 08:06 zirkelc

@j0k3r I would like to volunteer for this issue if you could give me a hint where the layer packaging happens?

zirkelc avatar Sep 30 '21 13:09 zirkelc

This is an issue with the serverless-webpack plugin. It still does not support lambda layers. Any idea when can we be expecting a fix on this?

gauravthantry avatar Dec 13 '21 01:12 gauravthantry

@zirkelc AFAIK there is no layer packaging logics anywhere in the codebase.

If anyone wants to work on this, I would recommend start studying how entries are generated validate.js#allEntryFunctions, you should add layer entries there. It then goes through compile.js.

After that, study packageModules.js and pick up your compiled layer bundles there.

vicary avatar Dec 13 '21 04:12 vicary

Same issue here.

renanz avatar Feb 17 '22 14:02 renanz

Any update on this issue?

komaldhiman07 avatar Sep 14 '23 18:09 komaldhiman07