This error occurs when npm can't find a workspace directory that's declared in your package.json. Usually caused by a typo in the workspaces glob, a deleted directory, or mismatched paths.
The "Missing workspace package" error (ENOENT) means your package.json declares workspaces that don't exist on the filesystem. npm reads the `workspaces` array, tries to find each matching directory, and fails when a path doesn't exist. This commonly happens when: - There's a typo in the workspace path or glob pattern - A workspace package was deleted but not removed from the config - The directory exists but doesn't contain a package.json - You're using a glob that doesn't match your directory structure
Check if the missing directory actually exists:
# List your packages directory
ls -la packages/
# Check if the specific package exists
ls -la packages/package-nameIf the directory doesn't exist, either create it or remove it from workspaces config.
Verify the paths in your root package.json:
{
"workspaces": [
"packages/*"
]
}Common mistakes:
- "packages" instead of "packages/*" (missing glob)
- "package/*" instead of "packages/*" (typo)
- Listing a specific package that doesn't exist
If you need to create the workspace:
# Create workspace with npm init
npm init -w ./packages/package-name
# This creates the directory AND a package.json inside itOr manually:
mkdir -p packages/package-name
cd packages/package-name
npm init -yEvery workspace directory must contain a valid package.json:
# Check for missing package.json files
for dir in packages/*/; do
if [ ! -f "$dir/package.json" ]; then
echo "Missing package.json in $dir"
fi
doneCreate missing package.json files:
cd packages/missing-package
npm init -yIf the workspace was intentionally deleted, remove it from package.json:
{
"workspaces": [
"packages/core",
"packages/cli"
]
}Then clean and reinstall:
rm -rf node_modules package-lock.json
npm installEmpty directories in Git: Git doesn't track empty directories. If a workspace was added but never had files committed, cloning the repo won't create that directory. Use a .gitkeep file:
touch packages/new-workspace/.gitkeepGlob debugging: Test what your glob pattern matches:
# See what packages/* would match
ls -d packages/*Package name vs directory name: The workspace is identified by its directory path, not the name in its package.json. packages/my-app must exist even if package.json says "name": "@scope/my-app".
Symlinks: If workspaces are symlinked, ensure the symlink target exists. Use ls -la to see where symlinks point.
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
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm