serverless-esbuild
serverless-esbuild copied to clipboard
Dependency Injection not working when using serverless-esbuild plugin
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']
Het @svetlasyrimis, thanks for raising it. Does it work in the deployed environment? Could you also try set all nestjs packages as external
Thanks for your prompt reply, will try that.
Using custom esbuild script to deploy, not sls.
I used @anatine/esbuild-decorators plugin as this example here: https://docs.serverless-stack.com/constructs/Function, and it solved the problem.
Thank you @vinicius91carvalho , will try that. So far still not working.
Update: Using esbuild-plugin-ts-decorators and plugins option in serverless.yaml actually made it work. Thanks for the help @vinicius91carvalho :)
Update: Using
esbuild-plugin-ts-decoratorsand 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
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()];
};