This document explains the changes made to fix the npm permission issues in the dev container.
The error you encountered was:
npm error code EACCES
npm error syscall mkdir
npm error path /workspace/node_modules/@ampproject
npm error errno -13
npm error Error: EACCES: permission denied, mkdir '/workspace/node_modules/@ampproject'
This occurred because the Docker volume for node_modules
was owned by the root user, but the container was running as the node
user, causing permission denied errors during npm install.
The following changes were made to fix the issue:
-
Modified
.devcontainer/docker-compose.yml
:- Changed the container to start as
root
user instead ofnode
- Added a command that ensures proper permissions on the
node_modules
directory before switching to thenode
user
- Changed the container to start as
-
Updated
.devcontainer/devcontainer.json
:- Modified the
postCreateCommand
to usechown
directly (without sudo) and run npm install as the node user
- Modified the
-
Updated
rebuild-devcontainer.sh
:- Updated to use modern
docker compose
syntax instead ofdocker-compose
- Added a step to start the container after rebuilding
- Added helpful messages about next steps
- Updated to use modern
To fix the npm permission issues, run the following command from your host machine (not inside the container):
chmod +x rebuild-devcontainer.sh && ./rebuild-devcontainer.sh
This script will:
- Stop any running containers
- Remove the node_modules volume
- Rebuild the container with the new configuration
- Start the container
After the script completes, you can reopen your project in the dev container and run npm install
again. The permission issues should be resolved.
If you still encounter permission issues after rebuilding:
- Open a terminal in the dev container
- Run:
ls -la /workspace/node_modules
to check permissions - If needed, ask your system administrator for help with Docker volume permissions