Runbook: npm install fails with EACCES on ebit-api/node_modules¶
Symptom¶
Running npm install in ebit-api/ on the host machine fails with:
Or similar permission errors when writing to node_modules/.
Likely cause¶
Older Docker builds ran as root inside the container and bind-mounted the source directory. This left node_modules/ owned by root:root on the host. When you later run npm install as your normal user, npm can't write to root-owned directories.
# Verify ownership
ls -la ebit-api/node_modules/ | head -5
# If you see "root root" instead of your username, this is the cause
Fix¶
# Fix ownership for all three repos
sudo chown -R $(whoami):$(whoami) \
ebit-api/node_modules \
ebit-fe/node_modules \
ebit-admin-fe/node_modules
# Retry
cd ebit-api && npm install
If node_modules/ doesn't exist yet (fresh clone), this error won't occur — just run npm install normally.
For ebit-fe / ebit-admin-fe (pnpm)¶
Same ownership fix applies if you see EACCES errors with pnpm.
Full cleanup (nuclear option)¶
If ownership is deeply nested or mixed:
# Remove and reinstall
sudo rm -rf ebit-api/node_modules
cd ebit-api && npm install
sudo rm -rf ebit-fe/node_modules ebit-fe/.next
cd ebit-fe && pnpm install
sudo rm -rf ebit-admin-fe/node_modules ebit-admin-fe/.next
cd ebit-admin-fe && pnpm install
Prevention¶
- The current
docker-compose.ymluses named volumes fornode_modulesinside containers (e.g.,node_modules_fe:/app/node_modules) instead of bind-mounting the host directory. This isolates container-ownednode_modulesfrom the host. - If you add a new Dockerfile that runs
npm installwith a bind-mounted source directory, ensure the container user matches the host user (or use a multi-stage build that copies artifacts instead of installing in-place). - Never run
sudo npm installon the host — it creates root-owned files that cause this exact problem.