Skip to content

Build failure in CodeBuild with node package download failure with HTTP 304

0

I have React project which is deployed using S3 and CloudFront. I use deployment pipeline which involves CodeBuild. Whole setup is in AWS ap-south-1 region. It has been working fine until today when I started to see build failures. I use a buildspec.yml file for the build process which is configured to issue a npm install command to setup the build environment. After investigation I found out that the download of one specific npm package is causing the issue. Following are the log entries of the offending package.

npm http fetch GET 304 https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz 1738ms (cache skip) npm warn tar TAR_BAD_ARCHIVE: Unrecognized archive format

This issue is not visible when the package is installed outside of the AWS environment. I even issued a npm cache clean --force command before the npm install command in the buildspec.yml. I have used both Ubutu and Amazon Linux distributions with no success. What could be the reason for this behavior which is only visible inside the CodeBuild?

asked 2 years ago508 views

3 Answers
1

The issue you're experiencing with CodeBuild failing to download a specific npm package is likely related to caching and network connectivity within the CodeBuild environment. The HTTP 304 status code indicates that the resource hasn't been modified since the last request, which suggests that CodeBuild is trying to use a cached version of the package.

Here are a few potential reasons and solutions for this behavior:

  1. Cached package: Despite using npm cache clean --force, CodeBuild might still be accessing a cached version of the package. Try adding npm cache verify before the npm install command in your buildspec.yml to ensure the cache is valid.

  2. Network issues: The CodeBuild environment might be experiencing temporary network connectivity problems when trying to download the package. You could try increasing the number of retries for npm by adding npm config set fetch-retries 5 before the install command.

  3. Registry mirror: CodeBuild might be using a different npm registry mirror that's having issues. You can explicitly set the registry URL in your buildspec.yml by adding npm config set registry https://registry.npmjs.org/ before the install command.

  4. Package integrity: The "Unrecognized archive format" error suggests that the downloaded package might be corrupted. You can try adding the --legacy-peer-deps flag to your npm install command to see if it resolves the issue.

  5. Version mismatch: Ensure that the package.json file in your project specifies the exact version of the problematic package to avoid any potential version conflicts.

If these solutions don't resolve the issue, you may want to consider using a different package manager like Yarn, or creating a custom Docker image for your build environment that includes pre-installed dependencies.

Remember that CodeBuild runs your builds in preconfigured environments, so issues that don't appear locally might still occur in the CodeBuild environment due to differences in configuration or network setup.
Sources
Managed Build Server - AWS CodeBuild Features - AWS
Troubleshooting AWS CodeBuild - AWS CodeBuild

answered 2 years ago

EXPERT

reviewed 2 years ago

1

Hi,

Can you try to clear your local package cache ? Please, use

rm -rf ~/.npm
mkdir ~/.npm

I have seen this fixing similar issues.

Best,

Didier

EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

0

Thank you @Didier for taking time to answer this question. Before I attempted your solution the issue corrected itself when I checked the pipeline again a short while ago without any changes. So, I am unable to try it out. But anyway, now it's fine. Thank you again.

For anyone who will be reading this in future, all the solutions given by the re:Post Agent didn't work when I tried them. You could try @Didier's solution to see if it changes anything.

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.