The ECANCELLED error occurs when npm init is interrupted, typically by pressing Ctrl+C during the interactive prompts. This is a user-initiated cancellation, not a system error.
ECANCELLED indicates the npm init process was intentionally stopped before completion. This happens when you press Ctrl+C (or Ctrl+Break on Windows) during the interactive questionnaire. npm init normally asks several questions (package name, version, description, etc.) and creates package.json based on your answers. Pressing Ctrl+C sends an interrupt signal that cancels the process. This is not a bug or system errorโit's npm acknowledging that you chose to stop the initialization. No package.json is created when cancelled.
Skip all prompts with -y flag:
npm init -y
# or
npm init --yesThis creates package.json with defaults:
- name: current directory name
- version: 1.0.0
- main: index.js
If you want to fill in details, answer all prompts:
npm init
# Answer each prompt:
package name: (my-project)
version: (1.0.0)
description: My awesome project
entry point: (index.js)
test command:
git repository:
keywords:
author: Your Name
license: (ISC) MIT
Is this ok? (yes) yesDon't press Ctrl+C until you see "Is this ok?"
Set defaults so npm init -y uses your info:
npm config set init-author-name "Your Name"
npm config set init-author-email "[email protected]"
npm config set init-license "MIT"
npm config set init-version "0.1.0"Now npm init -y uses these values.
If prompts freeze (known Node.js 8.1.0 bug):
# Check Node version
node --version
# If 8.1.0, upgrade:
nvm install 20
nvm use 20
# Then retry
npm initIf cancellation left partial files:
# Check if package.json exists
ls package.json
# If incomplete, remove and retry
rm package.json
npm init -yPlatform-specific issues:
Git Bash on Windows: Known to freeze after first input. Use npm init -y as workaround.
Windows PowerShell: May need double Ctrl+C to fully exit.
For scripts/CI, always use non-interactive mode:
npm init -yOr with specific values:
npm init -y --scope=@myorg
npm pkg set name="my-package" version="2.0.0"npm error code ENOENT npm error syscall spawn git npm error path git npm error errno -4058 npm error enoent An unknown git error occurred
How to fix "spawn git ENOENT" in npm
npm error code E401 npm error Incorrect or missing password.
How to fix 'E401 Unable to authenticate' errors with npm private registries
npm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm