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.
Fixes npm ERR! code EMPTYPACKAGE npm ERR! Empty package
cat package.jsoncat package.jsonnpm ERR! code EMPTYPACKAGEnpm ERR! Empty package
On this page
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.
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.
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.