- Newest
- Most votes
- Most comments
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:
-
Cached package: Despite using
npm cache clean --force, CodeBuild might still be accessing a cached version of the package. Try addingnpm cache verifybefore thenpm installcommand in your buildspec.yml to ensure the cache is valid. -
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 5before the install command. -
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. -
Package integrity: The "Unrecognized archive format" error suggests that the downloaded package might be corrupted. You can try adding the
--legacy-peer-depsflag to your npm install command to see if it resolves the issue. -
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
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
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
Relevant content
asked 2 years ago
- AWS OFFICIALUpdated 4 years ago
- AWS OFFICIALUpdated 5 years ago
