Docker Community Forums

Share and learn in the Docker community.

Npm error when add both "../:xxx" "./:xxx" to volumes

Hi ,I am using vscode container development.

I encountered a problem.I have solve that by comment volumes in .devcontainer/docker-compose.yml. But I don’t know what is causing this problem.

When I try exec npm i it will give me an error

Error: ENOENT: no such file or directory, uv_cwd
    at process.cwd (internal/process/main_thread_only.js:42:25)
    at process.cwd (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:10:19)
    at Conf.loadPrefix (/usr/local/lib/node_modules/npm/lib/config/load-prefix.js:46:24)
    at load_ (/usr/local/lib/node_modules/npm/lib/config/core.js:109:8)
    at Conf.<anonymous> (/usr/local/lib/node_modules/npm/lib/config/core.js:96:5)
    at Conf.emit (events.js:210:5)
    at ConfigChain._resolve (/usr/local/lib/node_modules/npm/node_modules/config-chain/index.js:281:34)
    at ConfigChain.add (/usr/local/lib/node_modules/npm/node_modules/config-chain/index.js:259:10)
    at Conf.add (/usr/local/lib/node_modules/npm/lib/config/core.js:338:27)
    at Conf.<anonymous> (/usr/local/lib/node_modules/npm/lib/config/core.js:314:25)
internal/process/main_thread_only.js:42
    cachedCwd = binding.cwd();
                        ^

Error: ENOENT: no such file or directory, uv_cwd
    at process.cwd (internal/process/main_thread_only.js:42:25)
    at process.cwd (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:10:19)
    at process.errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:181:30)
    at process.emit (events.js:210:5)
    at process._fatalException (internal/process/execution.js:150:25) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'uv_cwd'
}

The start command run by vscode is

[1806 ms] Start: Run: docker-compose -f c:\workspace\my_app\docker-compose.yml -f c:\workspace\my_app\.devcontainer\docker-compose.yml config --services

[4197 ms] Start: Run: docker-compose --project-name my_app -f c:\workspace\my_app\docker-compose.yml -f c:\workspace\my_app\.devcontainer\docker-compose.yml up -d --build

But If I comment volumes in .devcontainer/docker-compose.yml, the npm will work.

I wonder if there is any conflict between the two volumes?

Here are my files.

Dockerfile

FROM node:12.14.0-buster

WORKDIR /usr/app

docker-compose.yml

version: '3.7'
services:
  app:
    build: .
    volumes:
      - type: bind
        source: ../
        target: /usr/workspace

.devcontainer/docker-compose.yml

version: '3.7'
services:
  app:
    volumes:
      - .:/workspace:cached
    command: /bin/sh -c "while sleep 1000; do :; done"

I got same error. Try to add “working_directory” property in .devcontainer/docker-compose.yml.