You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As we have our own esbuild SAM build shoud not run npm install. Also, npm install does not seem to work with a monorepo. It tries to fetch the files from npm registry and thus requires .npmrc in all nested stacks. So, please add a flag to skip npm install. Would also be nice to be able to specify for some nested stacks that no build is needed as they are run in Docker containers.
I first use custom pre build scripts, which use esbuild. The in the SAM templates I use makesfiles to copy lambda source files. So no need for SAM build to install dependencies when build is already done and files copied.
Thank you for the additional information. Let's keep this issue open to collect more feedback and support from our community. We will prioritize the feature accordingly.
Context:
Our nodejs lambda already has its own npm run build command and is deployed using gitlab.
We wanted to plug AWS SAM to be able to test locally and to let developers deploy their own version of the service on our dev environment. However we did not want to change our current deployment pipeline to avoid a hard dependency with AWS SAM.
To achieve this goal, we had to add to the template.yaml:
Metadata:
BuildMethod: makefile
and in the makefile
build-ourLambdaFunction:
# Purpose: have the same build system for AWS SAM and Gitlab CI/CD
npm run build
cp ./dist/* $(ARTIFACTS_DIR)
I wanted to add the launch.json file at the root of the monorepo to be able to debug the lambda with breakpoints. When running it, it actually executes:
Closing this as a duplicate of #6567, which tracks the same request — a way to stop sam build from installing/updating dependencies when the project already manages them — and now carries a reproduction and the analysis of where the build time actually goes.
@tapz@rev42 the relevant findings for your setups, in short:
In a monorepo the nodejs install step resolves up to the workspace root, so the work is root-scoped and is repeated once per function. npm's cache does not help, because the cost is tree reconciliation rather than downloads.
With --build-in-source the install runs with --no-package-lock, so it ignores your lockfile and can silently change dependency versions in your source tree during a build. That part is a defect and I am preparing a fix in aws-lambda-builders.
sam build --cached cannot currently skip the install under --build-in-source — the internal "dependencies unchanged" path is unreachable in that mode. Fixing that is the change that gets monorepo builds fast without any new flag.
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
Activity
roger-zhangg commentedon Jan 24, 2025
Hi tapz, thanks for reaching out, do you mind explain the issue you have a bit more?
From what I perceive, if want to use esbuild in sam build, you can refer to this doc for using esbuild for sam build: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-build-typescript.html
And if esbuild is handling all the build, you can even skip the
sam buildand directly use the built assets for deploy or sync command.Please let me know,
Thanks
tapz commentedon Jan 25, 2025
I first use custom pre build scripts, which use esbuild. The in the SAM templates I use makesfiles to copy lambda source files. So no need for SAM build to install dependencies when build is already done and files copied.
vicheey commentedon Feb 17, 2025
Thank you for the additional information. Let's keep this issue open to collect more feedback and support from our community. We will prioritize the feature accordingly.
rev42 commentedon Apr 8, 2025
I'm in the same situation as @tapz
We are in a monorepo as well.
Context:
Our nodejs lambda already has its own
npm run buildcommand and is deployed using gitlab.We wanted to plug AWS SAM to be able to test locally and to let developers deploy their own version of the service on our dev environment. However we did not want to change our current deployment pipeline to avoid a hard dependency with AWS SAM.
To achieve this goal, we had to add to the template.yaml:
and in the makefile
I wanted to add the
launch.jsonfile at the root of the monorepo to be able to debug the lambda with breakpoints. When running it, it actually executes:The build is failing.
bnusunny commentedon Sep 27, 2026
Closing this as a duplicate of #6567, which tracks the same request — a way to stop
sam buildfrom installing/updating dependencies when the project already manages them — and now carries a reproduction and the analysis of where the build time actually goes.@tapz @rev42 the relevant findings for your setups, in short:
--build-in-sourcethe install runs with--no-package-lock, so it ignores your lockfile and can silently change dependency versions in your source tree during a build. That part is a defect and I am preparing a fix in aws-lambda-builders.sam build --cachedcannot currently skip the install under--build-in-source— the internal "dependencies unchanged" path is unreachable in that mode. Fixing that is the change that gets monorepo builds fast without any new flag.NodejsNpmEsbuildBuilder:NpmUpdatestep when using--build-in-sourcein a js/ts "monorepo" #6567, point 3.Please follow #6567 and add your use case there if it differs from what is described — a single thread is easier for us to prioritise than two.
NodejsNpmEsbuildBuilder:NpmUpdatestep when using--build-in-sourcein a js/ts "monorepo" #6567github-actions commentedon Sep 27, 2026
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.