Skip to content
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

Feature request: Skip npm install #7847

Open
tapz opened this issue Jan 24, 2025 · 4 comments
Open

Feature request: Skip npm install #7847

tapz opened this issue Jan 24, 2025 · 4 comments
Labels
stage/needs-feedback Needs feedback from the community (are you also interested in/experiencing this?) type/feature Feature request

Comments

@tapz
Copy link

tapz commented Jan 24, 2025

Describe your idea/feature/enhancement

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.

Proposal

Additional Details

@tapz tapz added stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. type/feature Feature request labels Jan 24, 2025
@roger-zhangg
Copy link
Member

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 build and directly use the built assets for deploy or sync command.

Please let me know,
Thanks

@roger-zhangg roger-zhangg added stage/needs-feedback Needs feedback from the community (are you also interested in/experiencing this?) and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Jan 24, 2025
@tapz
Copy link
Author

tapz commented 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
Copy link
Contributor

vicheey commented 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
Copy link

rev42 commented 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 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:

2025-04-08 14:43:00.067 [info] Command: (not started) [/usr/local/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctke35b9267/output --template /tmp/aws-toolkit-vscode/vsctke35b9267/app___vsctk___template.yaml --base-dir /home/node/lambdas/my-validator]
2025-04-08 14:43:00.700 [info] Building codeuri: /home/node/lambdas/my-validator runtime: nodejs20.x architecture: x86_64 functions: myvalidator
2025-04-08 14:43:00.748 [info] Running NodejsNpmBuilder:NpmPack
2025-04-08 14:43:10.844 [info] Running NodejsNpmBuilder:CopyNpmrcAndLockfile
2025-04-08 14:43:10.845 [info] Running NodejsNpmBuilder:CopySource
2025-04-08 14:43:10.848 [info] Running NodejsNpmBuilder:NpmInstall
2025-04-08 14:44:40.854 [error] SamLaunchRequestError: "sam build" failed. Timed out waiting for build. [BuildFailure]

The build is failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage/needs-feedback Needs feedback from the community (are you also interested in/experiencing this?) type/feature Feature request
Projects
None yet
Development

No branches or pull requests

4 participants