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 sync crashes when a "prepare" statement is in package.json #6835

Closed
maplion opened this issue Mar 15, 2024 · 6 comments
Closed

Bug: sam sync crashes when a "prepare" statement is in package.json #6835

maplion opened this issue Mar 15, 2024 · 6 comments
Labels
area/build sam build command area/sync sam sync command blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days

Comments

@maplion
Copy link

maplion commented Mar 15, 2024

Description:

sam sync crashes on loading when there is a "prepare" statement within "scripts" section of the package.json

Context:
I'm using the npm husky library (https://typicode.github.io/husky/get-started.html) as an "automated" way to have things done at commit time consistently among my team and it currently seems to break sam sync because of the "prepare": "husky" in the package.json that is required to be there to ensure everyone on the team installs it at least once for each repo/project.

Steps to reproduce:

  1. Install husky npm install --save-dev husky
  2. Setup husky npx husky init -- you should see a "prepare": "husky" added as a final "scripts" line within the package.json (if not, add it manually).
  3. Run sam sync for some template.yml

Observed result:

sam sync crashes with a Python error during startup -- this can be resolved by temporarily removing the prepare statement and starting again.

Expected result:

I expect sam sync to start as normal and ignore the prepare statement

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Windows 11
  2. sam --version: 1.108.0
  3. AWS region: us-east-1
{
  "version": "1.108.0",
  "system": {
    "python": "3.11.7",
    "os": "Windows-10-10.0.19045-SP0"
  },
  "additional_dependencies": {
    "docker_engine": "Not available",
    "aws_cdk": "Not available",
    "terraform": "Not available"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}
@maplion maplion added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Mar 15, 2024
@maplion maplion changed the title Bug: TITLE Bug: sam sync crashes when a "prepare" statement is in package.json Mar 15, 2024
@sidhujus
Copy link
Contributor

Hi @maplion, Thanks for opening the issue! I wasn't able to reproduce the error when I tried running sam sync after following the steps you posted. Could you try running sam sync with the --debug flag and providing the output here?

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

maplion commented Mar 15, 2024

@sidhujus

Here is the error I receive:

npm ERR! A complete log of this run can be found in: C:\Users\<user>\AppData\Local\npm-cache\_logs\2024-03-15T19_55_36_822Z-debug-0.log

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\sync\watch_manager.py", line 257, in _execute_infra_sync
    infra_sync_result = self._execute_infra_context(first_sync)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\sync\watch_manager.py", line 187, in _execute_infra_context
    return self._infra_sync_executor.execute_infra_sync(first_sync)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\sync\infra_sync_executor.py", line 168, in execute_infra_sync
    self._build_context.run()
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\commands\build\build_context.py", line 332, in run
    raise UserException(str(ex), wrapped_from=wrapped_from) from ex
samcli.commands.exceptions.UserException: NodejsNpmEsbuildBuilder:NpmInstall - NPM Failed: npm WARN config production Use `--omit=dev` instead.
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
'husky' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code 1
npm ERR! path C:\Users\<user>\AppData\Local\Temp\tmp8k6l4ov8
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c husky

@sidhujus
Copy link
Contributor

Spoke on slack, summarizing the workarounds here for visibility. When SAM CLI builds a node project it does not download the dev dependencies which is what causes the command not found error. specifying the --build-in-source flag bypasses this issue, additionally adding husky to the regular dependencies will also fix the problem. A third possible workaround is to follow the guidance provided here and set the command to never fail

@sidhujus sidhujus added area/build sam build command blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days and removed blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. labels Mar 15, 2024
@maplion
Copy link
Author

maplion commented Mar 27, 2024

I ended up using the "prepare":"husky || true" method to solve this as it seems to be the simplest and does what I need it to do without interruptions to sam sync or sam build. Both other methods were tried and work, but this was my preferred way to go about it. Closing this as I consider this a viable workaround. Thanks for the help @sidhujus !

@maplion maplion closed this as completed Mar 27, 2024
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

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.

@efimk-me
Copy link

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/sync sam sync command blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days
Projects
None yet
Development

No branches or pull requests

3 participants