AWS CodeArtifact Command Failed for NPM v9
Adam C. |

In the world of modern web development, keeping your tools and dependencies up to date is essential. Recently, I embarked on an upgrade journey, transitioning to npm v9 on my local machine. Little did I know that this seemingly innocuous upgrade would lead me to discover an issue with the AWS CodeArtifact command. In this blog post, I'll share my experience and the solution I found to make things right.

Photo by Jalal Kelink on Unsplash

The Problem Unveiled

It all started when I upgraded my local npm to version 9.0. The upgrade went smoothly, but soon I encountered a baffling issue with the AWS CodeArtifact command. A cryptic error message stared back at me:

Command '['npm', 'config', 'set', '//123.codeartifact.us-east-1.amazonaws.com
/npm/my-repo-name/:always-auth', 'true']' returned non-zero exit status 1.
 ELIFECYCLE  Command failed with exit code 255.

After some diligent investigation, I uncovered the root cause of the problem: NPM v9 had introduced a breaking change that affected the AWS CodeArtifact command.

The breaking change, as it turns out, was related to npm's configuration system. In NPM v9, the npm config set command no longer accepts deprecated or invalid config options. This change had a direct impact on the AWS CodeArtifact command, which relied on a specific npm configuration.

The NPM Configuration Conundrum

To clarify, when you use AWS CodeArtifact to install packages, it requires authentication. This authentication is achieved by setting an npm configuration that includes the :always-auth option. Here's an example of what that configuration looks like:

//123.codeartifact.us-east-1.amazonaws.com/npm/my-repo-name/:always-auth=true

This configuration is stored in your local ~/.npmrc file, and it is crucial for AWS CodeArtifact to function correctly.

With NPM v9, attempting to set this configuration using the npm config set command resulted in an error, as I experienced. This presented a serious obstacle to using AWS CodeArtifact with the latest NPM version.

The Solution: Upgrading AWS CLI

To resolve this predicament, the solution was clear: I needed to upgrade the AWS Command Line Interface (CLI) on my local machine. The version I had at the time was as follows:

$ aws --version
aws-cli/2.5.8 Python/3.9.11 Darwin/22.6.0 exe/x86_64 prompt/off

To upgrade AWS CLI to a version compatible with npm v9, I executed the following commands in my macOS terminal:

Download the latest AWS CLI package:

curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"

Install the downloaded package:

sudo installer -pkg ./AWSCLIV2.pkg -target /

After successfully upgrading AWS CLI to version 2.13.21, I retried the AWS CodeArtifact command, specifically npm run ca:login, and it worked flawlessly. The npm configuration was set as expected, and AWS CodeArtifact was back in action.