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
).
cd ~/Projects/my-local-package
npm i
npm run build
npm pack
Install local package in web app
cd ~/Projects/my-web-app
npm i ../my-local-package/my-local-package-1.0.0.tgz
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
When I'm not coding...
Me and Tina are on a motorcycle adventure around Australia.
Come along for the ride!