Testing an NPM package locally before you publish

Daniel Wild
1 min readFeb 17, 2020

Specifically — we’re talking about testing whether your package can be installed and consumed via npm as you originally intended (not testing business logic… although, you can do that too).

what about npm link?

npm link might be a passable option in some situations, however - as it relies on symlinks it can be problematic (e.g. some tools like webpack won’t always be honouring symlinks), and given that you’re not actually consuming the distribution artefact - it is not really a true test of whether your package will npm install as expected.

npm pack

The npm pack command produces the same .tgz artefact that is created and distributed by npm publish.

Therefore, a straightforward and reliable way to test your packages locally is simply to package your module for distribution, then try consuming it elsewhere.

e.g.

# enter pkg directory
cd /home/my-package
# build my-package-0.0.0.tgz
npm pack
# test pkg in another project
cd /home/my-other-project
npm install /home/my-package/my-package-0.0.0.tgz

--

--