How to fix npm ERR! code EMPTYPACKAGE npm ERR! Empty package in npm
The EMPTYPACKAGE error occurs when npm detects a package.json with missing required fields like 'name' or 'version', or when installing a package that was published with incomplete metadata.
Quick fix
Fixes npm ERR! code EMPTYPACKAGE npm ERR! Empty package
cat package.json- Verify your package.json exists and check its contents
- Recreate package.json with required fields
- Validate package.json syntax and required fields
- Clean cache and reinstall dependencies
cat package.jsonnpm ERR! code EMPTYPACKAGEnpm ERR! Empty package
What this error means
This error indicates that npm found a package.json file that either lacks essential required fields ('name' and 'version') or is completely empty/malformed. It can occur in two scenarios: when you try to install dependencies from a project with an invalid package.json, or when npm attempts to download a package from the registry that was published without proper metadata. The npm CLI validates package.json files to ensure they contain the minimum required fields before allowing installation or publication to proceed.
Typical symptoms
- npm install fails immediately without installing any dependencies
- Error message explicitly states 'EMPTYPACKAGE' with reference to a missing package.json or incomplete package metadata
- The package.json file exists but appears empty or contains only whitespace
- Running npm publish rejects your package with an EMPTYPACKAGE error
- Project dependencies fail to resolve because the package.json is missing critical fields
Common causes
- package.json file is completely empty or contains only whitespace/comments
- Required fields 'name' and 'version' are missing from package.json
- package.json is malformed JSON with syntax errors (unclosed braces, invalid quotes)
- A package was published to npm registry without required metadata in its package.json
- The package.json file was accidentally deleted or truncated by a failed operation
How to fix "npm ERR! code EMPTYPACKAGE npm ERR! Empty package"
First, navigate to your project root directory and check if package.json exists and contains valid content:
cat package.jsonYou should see output with at least a 'name' and 'version' field:
{
"name": "my-project",
"version": "1.0.0",
"description": "My project"
}If the file is empty or missing, proceed to the next step.
If your package.json is empty or missing, create a new one using npm init:
npm init -yThe -y flag automatically creates a default package.json with required fields populated. This command generates:
{
"name": "your-folder-name",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}Ensure your package.json has valid JSON syntax and contains the two required fields:
node -e "JSON.parse(require('fs').readFileSync('package.json', 'utf8'))"If this command succeeds silently, your JSON is valid. If you see an error, your package.json has syntax errors.
For a quick check that required fields exist, run:
npm lsIf it fails, it means name/version fields are missing or invalid.
After fixing your package.json, clean the npm cache and reinstall:
npm cache clean --force
rm -rf node_modules package-lock.json
npm installThis ensures npm downloads fresh copies of all dependencies and rebuilds your node_modules directory.
Advanced notes
The EMPTYPACKAGE error is relatively rare with modern npm versions but can occur when publishing malformed packages or when npm's internal validation is triggered on corrupted package.json files. If you're seeing this error consistently, check your Node.js and npm versions - older npm versions had more bugs around package.json handling. Run npm -v and node -v and consider upgrading with npm install -g npm@latest.
Frequently asked questions
- What does "npm ERR! code EMPTYPACKAGE npm ERR! Empty package" mean?
- json file that either lacks essential required fields ('name' and 'version') or is completely empty/malformed. json, or when npm attempts to download a package from the registry that was published without proper metadata. json files to ensure they contain the minimum required fields before allowing installation or publication to proceed.
- How do I fix "npm ERR! code EMPTYPACKAGE npm ERR! Empty package"?
- The EMPTYPACKAGE error occurs when npm detects a package.json with missing required fields like 'name' or 'version', or when installing a package that was published with incomplete metadata.
- What causes "npm ERR! code EMPTYPACKAGE npm ERR! Empty package"?
- package.json file is completely empty or contains only whitespace/comments Required fields 'name' and 'version' are missing from package.json package.json is malformed JSON with syntax errors (unclosed braces, invalid quotes)
- Is the "npm ERR! code EMPTYPACKAGE npm ERR! Empty package" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐
- ๐
- ๐ฌSO: node_modules appears empty(Stack Overflow)