Sometimes (very often) for a project, when cding into a subfolder of a docker volume I would get this error when trying to run any commands related to npm and node:
path.js:1077
path = process.cwd();
^
Error: ENOENT: no such file or directory, uv_cwd
at Object.resolve (path.js:1077:24)
at Function.Module._resolveLookupPaths (internal/modules/cjs/loader.js:534:17)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:629:20)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at /usr/local/lib/node_modules/npm/bin/npm-cli.js:19:21
at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:153:3)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
path = process.cwd();
^
Error: ENOENT: no such file or directory, uv_cwd
at Object.resolve (path.js:1077:24)
at Function.Module._resolveLookupPaths (internal/modules/cjs/loader.js:534:17)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:629:20)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at /usr/local/lib/node_modules/npm/bin/npm-cli.js:19:21
at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:153:3)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
which was extremely frustrating. Node works perfectly fine when not cding into a subdirectory but as soon as I cd inside them, node stops working. My command would look like this:
docker run --rm -v ${pwd}:/v node:10 bash -c "cd /v/Frontend; yarn dist"
which would throw the error. However, if I ran the command without cding, it would work:
docker run --rm -v ${pwd}:/v node:10 bash -c "cd /v; yarn dist"
The solution was to run this command first:
npm cache clean -f
after that it would work perfectly. So the final command would look like this:
npm cache clean -f; cd vol/Frontend; yarn dist