[BUG] "npm update check failed" error when running multiple "npm show" commands
What / Why
npm version 6.14.5 @ node version 14.4.0 @ Windows 10
I'm automating some tasks that involve checking npm dependencies and I'm running into random errors when issuing multiple npm commands simultaneously in multiple threads. Possible race condition accessing .config? Why would this be an issue for a read operation? (I'm only displaying package info, NOT updating any packages).
Repro steps
The following PowerShell script displays package info fetched from the npm catalog.
$packageIds = @(
@{Id = "gulp"},
@{Id = "npm"},
@{Id = "semver"},
@{Id = "webpack"},
@{Id = "typescript"},
@{Id = "yarn"}
)
Write-Host "Getting latest npm packages.."
$packageIds | ForEach-Object -throttleLimit 12 -parallel {
$package = $_
$packageId = $package["Id"]
# Get latest version from npm.
$latestVersion = Invoke-Expression ("npm show {0} version" -f $packageId)
# Get release date from npm.
$timestamps = Invoke-Expression ("npm show {0} time" -f $packageId)
$versionPattern = "'{0}':" -f $latestVersion
foreach ($timestamp in $timestamps)
{
if ($timestamp.Contains($versionPattern)) {
$releaseDate = $timestamp.Split(":")[1].Split("'")[1].Split("T")[0]
break;
}
}
# Print package name, version and date released.
Write-Host "$packageId $latestVersion released on $releaseDate"
}
- Save above powershell script as
Check.ps1. - Run
.\Check.ps1. (requires PowerShell Core version 7.0.2 or higher)
Expected 3. Packages are listed along with their latest published version and date of their release. Something like this:
gulp 4.0.2 released on 2019-05-06
semver 7.3.2 released on 2020-04-14
yarn 1.22.4 released on 2020-03-09
webpack 4.43.0 released on 2020-04-21
typescript 3.9.5 released on 2020-06-04
npm 6.14.5 released on 2020-05-04
Actual 3. Some of the time it works as expected, so you may have to run it multiple times. Sometimes (about 10-15% of the time?) it prints the following error:
┌────────────────────────────────────────────────────────────┐
│ npm update check failed │
│ Try running with sudo or get access │
│ to the local update config store via │
│ sudo chown -R $USER:$(id -gn $USER) C:\Users\xxxxx\.config │
└────────────────────────────────────────────────────────────┘
npm v6 is no longer in active development; We will continue to push security releases to v6 at our team's discretion as-per our Support Policy.
If your bug is preproducible on v7, please re-file this issue using our new issue template.
If your issue was a feature request, please consider opening a new RRFC or RFC. If your issue was a question or other idea that was not CLI-specific, consider opening a discussion on our feedback repo
Closing: This is an automated message.
npm v6 is no longer in active development; We will continue to push security releases to v6 at our team's discretion as-per our Support Policy.
If your bug is preproducible on v7, please re-file this issue using our new issue template.
If your issue was a feature request, please consider opening a new RRFC or RFC. If your issue was a question or other idea that was not CLI-specific, consider opening a discussion on our feedback repo
Closing: This is an automated message.