"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!