-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
esbuild (and TypeScript) Beta Support Feedback #3700
Comments
This is a very exciting feature, great work! Can we use the full esbuild API under BuildProperties? I'm trying to provide
Error after
|
Unfortunately we don't have support for the entire esbuild API, but having an option to set the aws-sdk as external definitely makes sense. Thanks for the feedback! |
Hi @mildaniel the feature certainly brings some handful build shortcuts when developing my lambdas in Typescript I also have the same question as @collindutter's. I would not like to have my dependencies bundled with my lambda function, I would like to use AWS Layers instead, how can I achieve this? |
Hey folks, just tried this out. Couple of pain points I found:
|
Thanks everyone, this is all great feedback. Just wanted to quickly address some of it:
|
Could you expand on this a little bit? The way it currently works is by installing the dependencies in the |
@mildaniel Yes what you said is correct but that would mean if I have 10 functions, I have to install esbuild as a dependency for each one. This is kinda backwards from how a normal JS project would be set up. Usually, there would be a top-level package.json that includes all your dev dependencies like esbuild, prettier, eslint etc. For example, this is how esbuild works in CDK atm - https://docs.aws.amazon.com/cdk/api/v1/docs/aws-lambda-nodejs-readme.html#local-bundling. One install of esbuild at the root package.json that is used for all functions. |
As a user, this is also one of my concerns... For me, one But it seems to me that it's not really necessary anymore because bundling with That said, changing a "shared" dependency will impact all functions that were using that dependency and cause a new redeployment. |
|
Would being able to mark that shared dependency as external and including it in a layer resolve this issue? |
@mildaniel I think so. But this behavior is not an issue for me, I just wanted to mention it. Personally, I try to use layers only for heavy dependencies or system dependencies, but not as a package manager. |
Does sam esbuild use the tsconfig for a project? I'm trying to set the My problem is very similar to this issue: evanw/esbuild#2044 |
With the recent support of ESM in Lambda, it could be nice to support the |
Another thing - with |
Support for esbuild plugins would be very helpful as currently this will only really work for pretty basic lambda functions. Being able to specify plugins for esbuild to use will allow compilation of certain typescript features that Evan has said that esbuild will never support, like decorators. As an example (pulled right from the issue linked above) - any project that uses TypeORM to access a database (or most of their alternatives, e.g. Sequelize in my use-case) cannot currently use native compilation and must stick to any current build process that exists. I'd love to switch to this as I have been looking to replace my webpack build process with esbuild for quite a while, since webpack is notoriously slow to build |
Adding to @collindutter, support for |
I’ve started submitting patches for |
Am I reading correctly (from above) that you cannot use typeORM with SAM (build) ? I get an error saying "aws_lambda_builders.actions.ActionFailedError: Esbuild Failed: ✘ [ERROR] Could not resolve "pg-native". exclude pg-native to resolve the issue. It is unclear to me where you would exclude it (in the SAM Build process) and if you exclude it would that resolve the problem? |
Until SAM supports both the |
This is a great feature and makes building for typescript super easy. Excluding external would solve our main issues with using it as well. Putting everything into one file makes you responsible for all the code in your dependencies, deprecation warnings and all so it can make things problematic when you have to use a dependency that cannot be updated as they get logged in the lambda and trigger alarms. |
The external flag option is definitely an important feature that we plan on adding. We're also looking into improvements of esbuild with accelerate to make that a smoother experience. Thank you for the feedback! |
Having watch mode would be incredibly helpful |
This is already part of accelerate which is usable with esbuild! Is there a reason for not using accelerate for iterating and testing? |
Hi @chris-armstrong! Thanks for all the great feedback. We were unable to reproduce what you talk about here ^ and I was wonderng if we can get on a call to get more specific repro steps? We would also love to get feedback from you as we are working towards the full GA launch of this feature. Please DM me here, and we can set something up. |
Is deduped build not working when setting Metadata? |
I have an issue to include custom layer Running NodejsNpmBuilder:CopyNpmrcAndLockfile
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc
Running NodejsNpmBuilder:LockfileCleanUp
Running NodejsNpmEsbuildBuilder:EsbuildBundle
Error: NodejsNpmEsbuildBuilder:EsbuildBundle - Esbuild Failed: ✘ [ERROR] Could not resolve "/opt/nodejs/database"
latest-posts.ts:4:24:
4 │ const sayName = require('/opt/nodejs/database')
╵ ~~~~~~~~~~~~~~~~~~~~~~
|
I get this error alot SAM CLI Team, please thoroughly test this functionality and apply the tool on other aws projects please. Dogfooding, you need it. This tool is great but it's reliability is still something less to be desired. |
Thanks everyone for the continued feedback, we really appreciate it. We understand the dependency bug is a real pain point for this feature and are looking into it. @erashdan this issue seems to be that esbuild is searching for the dependency on your machine but can't find it. Try setting those dependencies as |
Was the support for the |
Yes, support for |
The last esbuild features are awesome and really help us reduce some of the in-house tooling we wrote to support our projects. A couple of issues remain, and they might have an answer in the the current form but I'd appreciate any help here.
In standard backend project, you can have a giant node_modules directory which includes the "External" dependencies or some other static files. Is there a way you recommend doing this now? |
@praneetap I'm also experiencing very slow |
Hey @terrywarwar ! Thanks for reporting this. We are aware of the issue and working on a fix. |
Here's some feedback: getting unexpected configuration of sourcemaps in the build folder. Debugging with Typescript is not working because the source maps seem to be incorrectly configured. This is the file {
"version": 3,
"sources": ["../../../../../../../tmp/tmptvm1fyck/app.ts"],
"sourcesContent": ["import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';\n\n/**\n *\n * Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format\n * @param {Object} event - API Gateway Lambda Proxy Input Format\n *\n * Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html\n * @returns {Object} object - API Gateway Lambda Proxy Output Format\n *\n */\n\nexport const lambdaHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {\n let response: APIGatewayProxyResult;\n try {\n response = {\n statusCode: 200,\n body: JSON.stringify({\n message: 'hello world',\n }),\n };\n } catch (err) {\n console.log(err);\n response = {\n statusCode: 500,\n body: JSON.stringify({\n message: 'some error happened',\n }),\n };\n }\n\n return response;\n};\n"],
"mappings": "yaAAA,wDAYO,GAAM,GAAgB,KAAO,IAAgE,CAChG,GAAI,GACJ,GAAI,CACA,EAAW,CACP,WAAY,IACZ,KAAM,KAAK,UAAU,CACjB,QAAS,aACb,CAAC,CACL,CACJ,OAAS,EAAP,CACE,QAAQ,IAAI,CAAG,EACf,EAAW,CACP,WAAY,IACZ,KAAM,KAAK,UAAU,CACjB,QAAS,qBACb,CAAC,CACL,CACJ,CAEA,MAAO,EACX",
"names": []
} As you can see the sources point at You can reproduce this by using the hello-world example with sam init, and then attaching to the node process with this launch.json. {
"version": "0.2.0",
"configurations": [
{
"name": "Attach to SAM CLI",
"type": "node",
"request": "attach",
"address": "localhost",
"port": 9999,
"localRoot": "${workspaceRoot}/.aws-sam/build/HelloWorldFunction",
"remoteRoot": "/var/task",
"protocol": "inspector",
"stopOnEntry": false,
}
]
} |
Unable to set breakpoints in TypeScript code via VSCode I'm also experiencing the same problem as @jacobduba above in being unable to set debug breakpoints within the TypeScript code in the Hello World sample produced by sam init. In VSCode I see the error/warning:
Having done some troubleshooting I can see that when running sam build the app.js and app.js.map get produced in the .aws-sam/build/HelloWorldFunction/ directory, but like @jacobduba in the app.js.map file I see the sources path set to a relative path in a temp folder:
Browsing to that path shows the temp folder no longer exists. I'm running the latest Windows 10, I've tried the latest sam version (1.53.0) and the latest sam nightly (1.53.0.dev202208090902) but have the same issue with both. The troubleshooting in VSCode suggests that esbuild is producing the app.js.map with the wrong relative path. I've been unable to find the options we can pass into esbuild. Are there any esbuild options I can specify to adjust the relative path to allow me to set TypeScript breakpoints in VSCode? (e.g. in the template.yaml BuildProperties section or via command line for sam build?) |
@chris-fryer I submitted a PR that fixes the issue. |
One issue I have just encountered is again tied to the inability to access the entire esbuild API I think. I'm attempting to use uglifyjs and (as intended) esbuild does not resolve "require.resolve()" calls without a plugin to prompt it do so. My Lambda is now throwing:
from the following uglifyjs code (post esbuild bundling):
|
I'm finding it very hard to configure esbuild as I need it. As others have mentioned, the lack of plugin support is very limiting due to the Is there any way I can just tell |
Hey @samesfahani-tuplehealth. I understand where you're coming from with wanting to use the plugins API. There currently isn't a way to use it today, but I'll try to come up with a solution for this. Thank you for the continued feedback. |
Thanks for the quick response @mildaniel. As a workaround, in case this helps anyone, I just figured I could write my own script This workaround of course is completely side-stepping the feature at hand here, but it does 1) build and bundle your Javascript as you need it with plugins, exclusions, etc, 2) builds your artifact as Quick dirty example: build.tsimport { esbuildDecorators } from '@anatine/esbuild-decorators';
import { build } from 'esbuild';
build({
bundle: true,
entryPoints: ['src/app.ts'],
outdir: 'dist',
external: [
'pg-native',
],
format: 'cjs',
platform: 'node',
plugins: [
esbuildDecorators({ tsx: false, tsconfig: '../../tsconfig.json' }), // this feature is missing from current set of features!
],
sourcemap: true,
}); Again the only caveat is you set your @mildaniel In case this is useful, the serverless framework supports esbuild plugins through the following API: https://www.serverless.com/plugins/serverless-esbuild#esbuild-plugins Even in our codebase there are nuances with certain libraries needing static files copied over and as mentioned the decorator issue. While I do see the appeal in providing an abstraction over esbuild by exposing only the minimum required flags, inevitably someone is going to need some flag exposed or want some specific nuance. I fear that by the end of it, all of |
Thanks for providing a workaround @samesfahani-tuplehealth.
This is my thinking too. I will need to put some more thought into how exactly to support plugins through the SAM-CLI, bu ultimately would like to have support for something like this as well. |
I'm having trouble figuring out how to attach the IntelliJ debugger and breakpoints when using typescript. Using As for the debugger, so far I've tried:
|
@tunesmith yeah I also had a hard time getting the debug function to work as we have very little content/tutorials on that, but I managed to get that working - ofc there is a lot that can be done to improve the developer experience, but basically, you should be able to get the debug working on typescript by following this tutorial:
{
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to SAM Local Invoke",
"address": "localhost",
"port": 8066, //the port used when you trigger the function in debug mode
//Modify this to match the .aws-sam output from your function
"localRoot": "${workspaceRoot}/.aws-sam/build/DemoFunction",
"remoteRoot": "/var/task",
"skipFiles": [
"<node_internals>/**",
"/var/runtime/**/*.js",
"/var/runtime/node_modules/**",
],
"protocol": "inspector",
"stopOnEntry": false,
//Modify this to match the .aws-sam output from your function
"outFiles": ["${workspaceRoot}/.aws-sam/build/DemoFunction/**/*.js"]
},
]
}
Note: For every change you need to "rebuild" your lambda function, so you can use Please let me know if you need any extra help. |
I am testing esbuild with typescript and I get a strange behaviour when using layers. import uuid from 'uuid'; // This will be undefined and thus does not work
const uuid = require('uuid'); // This will work The problem is that using [EDIT]: Answering my own question: I needed to change my import to make it work
|
I have been now debugging the following error for a while ...
I could not find the reason why suddenly it was not finding my module I rename my initial
It works! I changed back the name to
It throws the above error... I then changed the name to something completely different It seems like there is a caching issue somewhere. |
This issue will be closed after collecting the separate feedback requests into individual issues. esBuild support is now GA. |
Hi all, In Thundra, we are also suffering from the same problem. Currently only workaround I see is that manually editing source map file to point to the workspace path ( Is there any other workaround and/or how we can automate this manual editing as part of |
@serkan-ozal, there aren't any automated ways of doing that today withing |
As @sriram-mv mentioned, this feature is now generally available. We appreciate everyone's feedback and have collected it all to plan our next steps for esbuild support! Please open a new issue in our repository for anything that comes up. |
I don't see how this could be marked as completed since it doesn't work with |
@sriram-mv The debugging is still not working in typescript as far as I can tell. Where is this issue being tracked? |
For Replace the Default value with packages names space separated with empty space
|
tytyty, this is exactly what i was looking for. |
Are esbuild plugins supported today? I'm going through the docs but haven't found any references. |
esbuild Support Beta
Recently, we added support for building Node.js and TypeScript lambda functions with esbuild. This allows for bundling and minification of Node.js functions and eases the process of writing TypeScript-based lambdas.
We now want to hear your feedback on the experience.
What feedback are we looking for?
The text was updated successfully, but these errors were encountered: