How to fix npm ERR! canceled in npm
The 'npm ERR! canceled' error occurs when npm abruptly terminates an operation, typically due to user interruption, network timeout, cache corruption, or missing packages in non-interactive environments.
Quick fix
Fixes npm ERR! canceled
npm cache clean --force
rm -rf node_modules
rm package-lock.json
npm install- Clear npm cache and reinstall from scratch
- Increase npm timeout settings
- Check your network and proxy settings
- Use npm ci instead of npm install (for CI/CD)
npm cache clean --forcerm -rf node_modulesrm package-lock.jsonnpm installnpm ERR! canceled
What this error means
The "npm ERR! canceled" error occurs when npm abruptly terminates a package installation or operation. This error is often vague—npm doesn't always clearly explain why the cancellation happened—but it typically indicates that a process was interrupted, failed to proceed, or encountered a condition that forced npm to stop. Unlike more specific errors (like network timeouts or missing packages), "canceled" is a catch-all that requires investigating the debug log and context to understand the root cause. The error commonly appears during npm install, npm ci, or npx commands. The error can stem from user intervention (pressing Ctrl+C), network problems, cache corruption, or missing packages in non-interactive environments.
Typical symptoms
- npm install hangs and then shows 'npm ERR! canceled' without further explanation
- CI/CD pipeline fails with 'npm ERR! canceled' during GitHub Actions or GitLab CI builds
- npx command cancels with 'npm ERR! canceled due to missing packages and no YES option'
- Install completes partially then aborts, leaving node_modules in an incomplete state
- Debug log exists but provides minimal detail about what triggered the cancellation
Common causes
- User pressed Ctrl+C or otherwise interrupted npm while installation was in progress
- Network timeout or connectivity dropped during package download
- npm cache is corrupted or contains invalid checksums, causing verification to fail
- npx running with --no-install flag but required packages aren't available locally (non-interactive env)
- Child process (like a build script) was killed or failed, causing npm to abort
- Insufficient disk space, permission issues, or system resource exhaustion
How to fix "npm ERR! canceled"
Corrupted cache is a common cause. Remove the cache and node_modules folder:
npm cache clean --force
rm -rf node_modules
rm package-lock.json
npm installThis forces npm to re-download all packages and verify checksums. You can also verify cache integrity before cleaning:
npm cache verifyNetwork timeouts commonly trigger canceled errors. Increase the timeout values:
npm config set fetch-timeout 1800000
npm config set fetch-retries 5
npm config set fetch-retry-mintimeout 120000
npm config set fetch-retry-maxtimeout 600000Or edit ~/.npmrc directly:
fetch-timeout = 1800000
fetch-retries = 5
fetch-retry-mintimeout = 120000
fetch-retry-maxtimeout = 600000These values give npm up to 30 minutes to fetch packages with 5 retries.
Verify your proxy configuration:
npm config get proxy
npm config get https-proxyIf these are set incorrectly, reset them:
npm config delete proxy
npm config delete https-proxyIf you need a proxy, configure it correctly:
npm config set proxy http://proxy.example.com:8080
npm config set https-proxy https://proxy.example.com:8080Temporarily disable VPN to verify it's not the cause.
In CI environments, use npm ci (clean install) instead of npm install:
npm cinpm ci uses exact versions from package-lock.json and fails more explicitly if there are issues.
For npx with missing packages, add --yes to auto-confirm:
npx --yes some-package@latestWhen npm prints 'npm ERR! canceled', it references a debug log. Find it:
A complete log of this run can be found in:
/home/user/.npm/_logs/2024-01-15T10_30_45_123Z-debug-0.logInspect the log file for more context:
cat ~/.npm/_logs/2024-01-15T10_30_45_123Z-debug-0.logLook for error keywords like 'ETIMEDOUT', 'ERR_SOCKET_TIMEOUT', 'permission denied', or 'signal SIGINT'.
Insufficient disk space can trigger cancellations mid-install:
df -hEnsure you have at least 1-2 GB free. If disk is low, clear unnecessary files:
# macOS
rm -rf ~/Library/Caches/npm
# Linux
rm -rf ~/.npmAlso verify your system has enough memory. Large projects need adequate RAM.
Advanced notes
Signal Handling & Interrupts: When you press Ctrl+C during npm install, npm receives SIGINT. Older versions of npm didn't handle this cleanly. Modern npm (v7+) respects the signal but may take time to gracefully shut down. A second Ctrl+C sends SIGKILL, which terminates immediately.
It's safe to interrupt npm install—npm v3+ automatically repairs node_modules if interrupted, so re-running npm install will fix any partial state.
CI/CD Specifics: In GitHub Actions, npx --no-install combined with a missing package triggers "npx canceled due to missing packages and no YES option". The solution is either: (a) pre-install the package with npm install, (b) use npx --yes, or (c) install globally.
Network Resilience: Transient network hiccups can cancel an install. npm has built-in retry logic, but the default retry counts may be conservative. Increasing fetch-retries to 5+ and fetch-retry-maxtimeout to 10+ minutes helps with unreliable networks.
Frequently asked questions
- What does "npm ERR! canceled" mean?
- The "npm ERR! canceled" error occurs when npm abruptly terminates a package installation or operation. This error is often vague—npm doesn't always clearly explain why the cancellation happened—but it typically indicates that a process was interrupted, failed to proceed, or encountered a condition that forced npm to stop.
- How do I fix "npm ERR! canceled"?
- The 'npm ERR! canceled' error occurs when npm abruptly terminates an operation, typically due to user interruption, network timeout, cache corruption, or missing packages in non-interactive environments.
- What causes "npm ERR! canceled"?
- User pressed Ctrl+C or otherwise interrupted npm while installation was in progress Network timeout or connectivity dropped during package download npm cache is corrupted or contains invalid checksums, causing verification to fail
- Is the "npm ERR! canceled" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚npm Official Documentation
- 📖npm docs: npm install(Official Docs)
- 🐙GitHub: npm canceled issues(GitHub)
- 💬Stack Overflow: npm canceled(Stack Overflow)