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

Bug: sam build Ignores Files in dist/ Directory When Specified in .gitignore #7402

Open
hcz1 opened this issue Aug 24, 2024 · 2 comments
Open
Labels
area/build sam build command area/node-npm blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.

Comments

@hcz1
Copy link

hcz1 commented Aug 24, 2024

Title: sam build Ignores Files in dist/ Directory When Specified in .gitignore

Description

Issue Summary

When specifying the dist/ directory in the .gitignore file, the sam build process also ignores the files in this directory. This behaviour causes issues when the build output is expected to be in the dist/ directory, as the necessary files are not included in the build.

Steps to Reproduce

  1. Create a Node.js project with AWS SAM.
  2. Add a .gitignore file with the following content:
    dist/
  3. Configure the project to output build files to the dist/ directory.
  4. Run the sam build command.

Expected Behaviour

The sam build process should include the files in the dist/ directory, even if it is specified in the .gitignore file, as the .gitignore file should only affect Git operations.

Actual Behaviour

The sam build process ignores the files in the dist/ directory, causing the dist folder not to be copied to .aws-sam/build/function_name/.

Workaround

Removing the dist/ entry from the .gitignore file allows the sam build process to include the necessary files, but this is not an ideal solution as it causes the dist/ directory to be tracked by Git.

Environment

SAM CLI Version: 1.123.0
Node.js Version: v20.9.0
OS: 14.3 (23D56)

Additional Context

My build process is to run tsc && sam build && sam deploy, the lambda handler is set to dist/path_to_handler.

@hcz1 hcz1 added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Aug 24, 2024
@lucashuy
Copy link
Contributor

lucashuy commented Aug 28, 2024

Hi, normally sam build is capable of building your Typescript project using esbuild as a build method (docs). Using tsc to perform a "preprocessing" build, then using sam build will have unintended side effects depending on the project structure.

Namely, that sam build will have it's own build process that may or may not include the dist folder. sam build will call npm pack under the hood to create a "production" ready copy of the project. npm pack will ignore any files that is listed in either .gitignore, or .npmignore, preferring to use .npmignore if both files exist. This may be the root cause of the issue you are facing.

Can you provide a sample project that utilizes your build process to help us further diagnose?

@lucashuy lucashuy added blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. area/build sam build command area/node-npm and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Aug 28, 2024
@hcz1
Copy link
Author

hcz1 commented Aug 28, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build sam build command area/node-npm blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.
Projects
None yet
Development

No branches or pull requests

2 participants