Docker volume mount overwrite npm local package symlink bug?

Viewed 17

I Have a monorepo for full stack Typescript webapp, with the following structure:

/shared/package.json
/shared/<source files, node_modules etc>

/server/package.json
/server/<source files, node_modules etc>

/client/package.json
/client/<source files, node_modules etc>

The shared package is installed into the server and client packages using npm install ../shared which among other things, creates a symlink in the given package's node_modules to the /shared package folder. Normally this works nicely.

If I use COPY . . in the Dockerfile, it still works nicely, I would like to build the docker image this way, for deploying. If I don't use COPY . . but instead docker volume mounting, this still works nicely, I use the mounted variant for development environment defined in docker-compose.yml that starts the server, cliend, db and other infra containers together.

The problem arises when I use a Dockerfile in the compose.yml that contains the COPY . . part AND try to mount host volume overwriting what was COPY-ed during the image building. In this case everything still works, except npm can't resolve referenced files through the symlinks inside the node_modules directory, even though, both on the host and in the container terminal ls -l correctly sees the symlink, and cd the-symlinked-dir can correctly step through the symlink.

Environment: the host is on WSL subsystem (the 'host' folders are inside the wsl volume, not the mounted windows volume) and the used docker image is also default linux based nodejs image so the symlinks should both be of the same linux flavor? (not sure how I could check this).

Currently the best solution I could come up for this is to just define and maintain 2 separate Dockerfiles for every package, one for the dev environment, one for deployment.

Is there some additional configuration missing? Maybe for docker or a nodejs / npm setting that avoids the use of symlinks that I cant find? (eg.: in dotnet world, project references in a monorepo just point to the other project's path and the tooling knows to watch / build / copy the referenced projects code, without symlinks, following the path).

Notes / other things I tried for the monorepo approach: Typescript projects and project references are not yet suitable for this kind of codesharing, as non tsc tooling (eg babel for react...) do not yet support them. NPM workspaces are also not a solution, as they still deal with local package references using symlinks in the now centralised node_modules dir. AFAIK Lerna also is built on symlinks, it just streamlines the process (didn't yet try this one, as I never used Lerna before, just based on their docs).

0 Answers
Related