AWS SAM - template initialization failure for typescript projects on windows
Objective:
Create a Nodejs14.x based typescript project.
Issue:
Unable to clone from the [aws-sam-cli-app-templates](https://github.com/aws/aws-sam-cli-app-templates) repository on a windows 10 machine.
Error:
Cloning from https://github.com/aws/aws-sam-cli-app-templates (process may take a moment)
Clone error, attempting to use an old clone from a previous run
Template is not provided in context, skip adding project type metric
Steps to reproduce:
sam init --debug
2022-03-28 17:28:28,269 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2022-03-28 17:28:28,269 | Using config file: samconfig.toml, config environment: default
2022-03-28 17:28:28,270 | Expand command line arguments to:
2022-03-28 17:28:28,271 | --package_type=Zip --output_dir=.
You can preselect a particular runtime or package type when using the `sam init` experience.
Call `sam init --help` to learn more.
Which template source would you like to use?
1 - AWS Quick Start Templates
2 - Custom Template Location
Choice: 1
Choose an AWS Quick Start application template
1 - Hello World Example
2 - Multi-step workflow
3 - Serverless API
4 - Scheduled task
5 - Standalone function
6 - Data processing
7 - Infrastructure event management
8 - Machine Learning
Template: 1
Use the most popular runtime and package type? (Python and zip) [y/N]: n
Which runtime would you like to use?
1 - dotnet6
2 - dotnet5.0
3 - dotnetcore3.1
4 - go1.x
5 - java11
6 - java8.al2
7 - java8
8 - nodejs14.x
9 - nodejs12.x
10 - python3.9
11 - python3.8
12 - python3.7
13 - python3.6
14 - ruby2.7
Runtime: 8
What package type would you like to use?
1 - Zip
2 - Image
Package type: 1
Based on your selections, the only dependency manager available is npm.
We will proceed copying the template using npm.
Select your starter template
1 - Hello World Example
2 - Hello World Example TypeScript
Template: 2
Project name [sam-app]: samp-app-ts
Cloning from https://github.com/aws/aws-sam-cli-app-templates (process may take a moment)
Observed result:
Clone error, attempting to use an old clone from a previous run
Template is not provided in context, skip adding project type metric
Sending Telemetry: {'metrics': [{'commandRun': {'requestId': 'f5ed9e57-b3ec-4562-9884-a786e04d3875', 'installationId': 'e8ece184-b9f0-4387-b72d-4dfc47514a8e', 'sessionId': 'aac963c0-31bc-4ee1-b949-4dbaaeac5b55', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.8', 'samcliVersion': '1.42.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam init', 'duration': 27215, 'exitReason': 'InvalidInitTemplateError', 'exitCode': 1}}]}
Telemetry response: 200
Error: Can't find application template hello-world-typescript - check valid values in interactive init.
Expected result:
-----------------------
Generating application:
-----------------------
Name: sam-app-ts
Runtime: nodejs14.x
Architectures: x86_64
Dependency Manager: npm
Application Template: hello-world-typescript
Output Directory: .
Next steps can be found in the README file at ./sam-app-ts/README.md
Commands you can use next
=========================
[*] Create pipeline: cd sam-app-ts && sam pipeline init --bootstrap
[*] Test Function in the Cloud: sam sync --stack-name {stack-name} --watch
Additional environment details
- OS: Windows 10
sam --version: 1.42.0- AWS region: us-east-1
Temporary work around
For any of you facing this issue if you need to make this work
- Go to C:\Users\[your-username]\AppData\Roaming\AWS SAM
- git clone https://github.com/aws/aws-sam-cli-app-templates
- go back to the location where you initially ran the
sam initcommand and try again.
Thanks for reporting this issue.
The root cause is coming from the Windows path limitation. We would recommend enabling long paths by running following commands;
-
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force -
git config --system core.longpaths true
We will also work on this to give more appropriate error message so that users can fix the issue.
With https://github.com/aws/aws-sam-cli-app-templates/pull/326 in place. This error should not show up anymore.
⚠️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.