`Error: Cannot find module` in container but works on the host.
IntermediateTroubleshootingContainers that exit, crash or misbehave
Answer
Likely causes → node_modules excluded by .dockerignore but npm install not run, a bind mount shadowing /app/node_modules, or platform-specific native modules built on the host.
Diagnose →
docker run --rm image ls /app/node_modules | head
docker inspect -f '{{json .Mounts}}' c
Fix → Install dependencies in the image, mask node_modules with a named volume when bind mounting, never copy host node_modules.
Prevent → .dockerignore with node_modules and npm ci in the Dockerfile.
More on Containers that exit, crash or misbehave
Container exits immediately with code 0 right after `docker run -d`.Beginner`Exited (137)` with no OOM flag.Intermediate`Exited (139)` segmentation fault.Advanced`Exited (126)` / `Exited (127)`.Beginner`exec /entrypoint.sh: exec format error`Intermediate`docker run` says `WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8)` and the app is very slow.Beginner