Published: March 10 2024

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.

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

 


Need Some NodeJS Help?

Search fiverr for freelance NodeJS developers.


Follow me for updates

On Twitter or RSS.


When I'm not coding...

Me and Tina are on a motorcycle adventure around Australia.
Come along for the ride!


Comments


Supported by