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

Dependency Injection not working when using serverless-esbuild plugin

Open svetlasyrimis opened this issue 3 years ago • 7 comments

Hello,

I've encountered that weirdly dependency injection breaks(Nest.js project) when attempting to use serverless-esbuild in local environment. However when attempting to use serverless-webpack it's all working fine.

[email protected] [email protected] [email protected] [email protected]

custom:
  serverless-offline:
    httpPort: 4000
    lambdaPort: 4001
  esbuild:
    bundle: true
    minify: false
    platform: 'node'
    external:
      - "cache-manager"
      - "class-transformer"
      - "class-validator"
      - "@nestjs/microservices"
      - "@nestjs/websockets/socket-module"
      - "fastify-swagger"
    watch:
      pattern: ['src/**/*.ts']

svetlasyrimis avatar Feb 01 '22 15:02 svetlasyrimis

Het @svetlasyrimis, thanks for raising it. Does it work in the deployed environment? Could you also try set all nestjs packages as external

floydspace avatar Feb 01 '22 15:02 floydspace

Thanks for your prompt reply, will try that.

Using custom esbuild script to deploy, not sls.

svetlasyrimis avatar Feb 01 '22 17:02 svetlasyrimis

I used @anatine/esbuild-decorators plugin as this example here: https://docs.serverless-stack.com/constructs/Function, and it solved the problem.

vinicius91carvalho avatar Feb 11 '22 21:02 vinicius91carvalho

Thank you @vinicius91carvalho , will try that. So far still not working.

svetlasyrimis avatar Feb 11 '22 23:02 svetlasyrimis

Update: Using esbuild-plugin-ts-decorators and plugins option in serverless.yaml actually made it work. Thanks for the help @vinicius91carvalho :)

svetlasyrimis avatar Feb 17 '22 14:02 svetlasyrimis

Update: Using esbuild-plugin-ts-decorators and plugins option in serverless.yaml actually made it work. Thanks for the help @vinicius91carvalho :)

@svetlasyrimis Am i missing something? how do you use esbuild-plugin-ts-decorators in the serverless.ts file

Bnic3 avatar Oct 21 '23 16:10 Bnic3

This is what she meant by

serverless.yml

  esbuild:
    plugins: esbuild-plugins.js
    bundle: true
    minify: true
    sourcemap: true
    external:
      - 'class-transformer'
      - 'class-validator'
      - '@nestjs/microservices'
      - '@nestjs/websockets/socket-module'

      - 'cache-manager'
      - 'fastify-swagger'

esbuild-plugins.js

/* eslint-disable @typescript-eslint/no-var-requires */
const { esbuildDecorators } = require('esbuild-plugin-typescript-decorators');

module.exports = () => {
 return [esbuildDecorators()];
};

senghuotlay avatar Apr 07 '24 01:04 senghuotlay