"TS2307: Cannot find module" with custom modules-folder in yarn

Sometimes we may choose to change the default location of the node modules folder when we work with yarn to benefit from some form of caching (e.g. in CI).

It's as simple as writing --modules-folder /var/cache/node_modules to .yarnrc in the root of a project.

When node packages live outside the project repository, our build may start failing unable to find typings for libraries even if they are present in the package.json file.

TS2307: Cannot find module 'lodash'

To work around this issue, create a node_modules symlink pointing to the custom installation location defined in your .yarnrc file.

ln -s /var/cache/node_modules node_modules

The build should be working again!

Seamless docker

Today I learned docker container can act as if it was an application running on the host system with little effort

# Build docker image
$ docker build -t seamless-docker .

# Run a process in an isolated container
$ docker run --net host --volume `pwd`/shared:/shared seamless-docker

Let's break it down:

--net host exposes host network to the container helping the program running in the container act as if it was running in the host system.

--volume `pwd`/shared:/shared creates a shared volume between the host system and the container. It supports writes unless we add :ro  at the end. Any time modification is made in the host system or the container, the other will get the update.

Note:

By default Docker Desktop on MacOS does not allow creating a shared volume unless the directory is whitelisted. Some directories are whitelisted by default. File Sharing preferences can be changed in Docker -> Preferences -> File Sharing