npm pack for local package dependency testing


Steps to test npm package dependencies locally without publishing to npm.

Installing the packed tarball works exactly like installing a package from an npm repo whereas linking to the local package with npm link doesn’t always behave the same as a real repo.

Table of Contents

Build and pack local package

The npm pack command generates a tarball (.tgz) of the built project with the name and version from the package.json file (e.g. my-local-package-1.0.0.tgz).

  1. cd ~/Projects/my-local-package
  2. npm i
  3. npm run build
  4. npm pack

Install local package in web app

  1. cd ~/Projects/my-web-app
  2. npm i ../my-local-package/my-local-package-1.0.0.tgz
  3. npm start

Extra step for Next.js apps

Might need to clear the Next.js cache by deleting the .next/cache folder before installing the local package (step 2 above).

rm -rf .next/cache

Ā 


Share this content:

I am a passionate blogger with extensive experience in web design. As a seasoned YouTube SEO expert, I have helped numerous creators optimize their content for maximum visibility.

Leave a Comment