Open jrglg opened 1 year ago
Palle gave me a quick fix: https://jovodevs.slack.com/archives/C01RH3TMPFF/p1669802643125869?thread_ts=1669802525.160419&cid=C01RH3TMPFF
I had a Gitlab pipeline, so to keep it working I deleted the bundle
script,
then I added a few more config to be like Jovo build npm script:
const {build} = require("esbuild");
const {esbuildDecorators} = require("@anatine/esbuild-decorators");
build({
platform: "node",
target: "node14",
bundle: true,
sourcemap: true,
minify: true,
keepNames: true,
format: "cjs",
tsconfig: __dirname + '/tsconfig.json',
entryPoints: [`${__dirname}/${process.argv[2]}`], // the name of the ts stage app file
outfile: "bundle/index.js",
external: [
"aws-sdk",
"@oclif/:*",
"@jovotech/cli*",
"@alexa/*",
"mongodb-client-encryption", // if you use MongoDb Jovo integration
],
plugins: [
esbuildDecorators({
tsconfig: __dirname + "/tsconfig.json",
cwd: process.cwd(),
})
]
});
and changed the deploy:STAGE
script to node build.js src/app.STAGE.ts
.
So far it's working.
Hey @palle-k can you explain what the issue is and why the fix works?
@rmtuckerphx esbuild doesn't emit decorator metadata like the normal typescript compiler does. This metadata includes data like the arguments that a constructor has, including the argument types.
The dependency injection system requires this metadata to instantiate classes. That's also the reason why types need to be annotated with @Component
or @Injectable
for dependency injection to work.
This build script restores decorator metadata by compiling files that include decorators with the normal typescript compiler instead of esbuild.
This is how I updated package.json
:
"bundle": "node build.js",
Here is the code for build.js
:
const { build } = require('esbuild');
const { esbuildDecorators } = require('@anatine/esbuild-decorators');
const entryPoint = process.argv[2];
console.log('build entry point:', entryPoint);
build({
bundle: true,
outfile: 'bundle/index.js',
sourcemap: true,
minify: true,
keepNames: true,
platform: 'node',
target: 'node14',
format: 'cjs',
external: ['aws-sdk', '@oclif/*', '@jovotech/cli*'],
entryPoints: [entryPoint],
plugins: [
esbuildDecorators({
tsconfig: './tsconfig.json',
cwd: process.cwd(),
}),
],
});
@aswetlow You should add to docs for projects built with Dependency Injection that are deployed to Lambda
Even though this is kind of an old issue, I just wanted to add, that I recently found out, that for our projects the esbuildDecorators
leads to sourcemaps being out of sync. If I am working with this plugin, and throw an error, the line number of the ts file in the error message will be incorrect. Commenting the plugin out will fix this issue. Did any of you who are using this experience something similar?
I'm submitting a...
Expected Behavior
Dependency injection system should work in Lambda as it's working in Express.
Current Behavior
A simple Jovo project (starting template) with an injected service doesn't work in Lambda because injections are
undefined
.I attach an example project to test this out.
Error Log
Your Environment
Jovo Framework version used: @jovotech/cli/4.1.8 win32-x64 node-v14.21.1
Operating System: Windows 10
Example project
test.zip