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.
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.
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files
How to fix 'npm ERR! code EMPTYPACKAGE' - Package contains no files
npm ERR! code EWORKSPACEMISSING npm ERR! Workspace does not exist: packages/missing
How to fix "npm ERR! code EWORKSPACEMISSING - Workspace does not exist" error
npm ERR! code EADDRNOTAVAIL npm ERR! errno EADDRNOTAVAIL npm ERR! Address not available
How to fix "npm ERR! code EADDRNOTAVAIL - Address not available" error