Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Manson's avatar

Error: Cannot find module '/var/www/html/run'

I am trying to build a new Laravel project with Vue and Inertia in Docker.

I can build the docker image, but when I try to run docker-compose run --rm npm run dev

I got this error

[+] Building 0.0s (0/0) docker:desktop-linux [+] Building 0.0s (0/0) docker:desktop-linux node:internal/modules/cjs/loader:1051 throw err; ^

Error: Cannot find module '/var/www/html/run' at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15) at Module._load (node:internal/modules/cjs/loader:901:27) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12) at node:internal/main/run_main_module:23:47 { code: 'MODULE_NOT_FOUND', requireStack: [] }

Node.js v20.5.1

and this is my docker yml file

version: '3.8'

services: nginx: build: context: . dockerfile: nginx.dockerfile args: - UID=${UID:-1001} - GID=${GID:-1001} ports: - 8083:8083 volumes: - ./src:/var/www/html networks: - default depends_on: - mysql - php mysql: image: mysql:8.0 ports: - 3310:3306 environment: MYSQL_DATABASE: testing MYSQL_USER: admin MYSQL_PASSWORD: secret MYSQL_ROOT_PASSWORD: secret volumes: - ./mysql:/var/lib/mysql:rw php: build: context: . dockerfile: php.dockerfile args: - UID=${UID:-1001} - GID=${GID:-1001} volumes: - ./src:/var/www/html composer: build: context: . dockerfile: composer.dockerfile volumes: - ./src:/var/www/html working_dir: /var/www/html npm: image: node:current-alpine volumes: - ./src:/var/www/html #entrypoint: ["npm"] working_dir: /var/www/html command: ["npm", "run", "watch"] networks: - default artisan: build: context: . dockerfile: php.dockerfile args: - UID=${UID:-1001} - GID=${GID:-1001} volumes: - ./src:/var/www/html working_dir: /var/www/html depends_on: - mysql entrypoint: ["php", "/var/www/html/artisan"]

this is the package.json

{ "private": true, "type": "module", "scripts": { "dev": "vite", "build": "vite build", "watch": "vite --watch" }, "devDependencies": { "@vitejs/plugin-vue": "^5.0.4", "axios": "^1.6.4", "laravel-vite-plugin": "^1.0.2", "vite": "^5.0", "vue": "^3.4.21" }, "dependencies": { "@inertiajs/inertia": "^0.11.1", "@inertiajs/inertia-vue3": "^0.6.0" } }

0 likes
1 reply
LaryAI's avatar
Level 58

Based on the error message and the provided docker-compose.yml file, it seems like there might be an issue with the way the npm command is being run within the Docker container. The error message suggests that Node.js is trying to find a module at /var/www/html/run, which is not the expected behavior when running npm run dev.

Here's a step-by-step solution to troubleshoot and potentially fix the issue:

  1. Check the Working Directory: Ensure that the working directory is correctly set to the root of your Laravel project where the package.json file is located. In your docker-compose.yml file, it seems to be set correctly with working_dir: /var/www/html.

  2. Check the Volume Bindings: Make sure that the volume bindings are correctly mapping your local project directory to the /var/www/html directory inside the container. This is crucial for the container to access the package.json file and run the npm scripts.

  3. Check the Entrypoint and Command: The npm service in your docker-compose.yml file has a commented out entrypoint and a command that is set to ["npm", "run", "watch"]. If you want to run npm run dev, you should either uncomment the entrypoint and use docker-compose run --rm npm run dev, or change the command to ["npm", "run", "dev"].

  4. Check the Dockerfile: Ensure that the Dockerfile used to build the npm service image does not have any entrypoint or command that could be conflicting with what you are trying to run.

  5. Check the Node.js Version: Make sure that the version of Node.js in your Docker container is compatible with your project dependencies.

  6. Run the Command Manually: Try to run the command manually inside the container to see if it works. You can do this by first starting a shell inside the container:

docker-compose run --rm npm sh

Then, once inside the container, try running:

npm run dev

If this works, the issue might be with how the command is being passed in docker-compose.

Here's a revised docker-compose.yml snippet for the npm service that you can try:

npm:
  image: node:current-alpine
  volumes:
    - ./src:/var/www/html
  working_dir: /var/www/html
  command: ["npm", "run", "dev"]
  networks:
    - default

Make sure to rebuild your Docker images and containers after making changes to the docker-compose.yml file:

docker-compose up --build

If none of these steps resolve the issue, please provide more details about your Docker setup, including the contents of the Dockerfiles, so that we can further assist you.

Please or to participate in this conversation.