Installing local NPM packages with Yarn
I’ve been publishing my first NPM packages lately and have deeded to install NPM packages locally for testing. There are two ways to do this and they both have their separate use cases.
Using yarn add
First, you can install local packages with Yarn simply by giving the package path as argument for add:
yarn add /path/to/my/package
This installs the package as any other package by copying it to your
node_packages. This has the benefits of working exactly as any normal package but the downside of being an actual copy (instead of symlink) of your local project. If you want to test and develop your local project, you might want to try linking instead.
If you use this method for developing, you need to yarn add the path again whenever you want to test new changes.
Using yarn link
Yarn (like npm) has link command that allows you to symlink any local NPM package in your project. This is very handy for fast development and testing but also the downside of the linked package not being physically in your node_modules which can break some functionality (that relies on looking up parent paths).
Linking a local module happens in two steps:
yarn linkin the project you want to link
yarn link "package-name"wherever you want to link it to