How to Publish NPM Package to npmjs.com
Table of Contents
- Introduction
- Quick Release Commands
- Confirm npm Account and Scope Access
- Validate Package Metadata
- Build and Test Before Publish
- Verify What Will Be Published
- Bump Version
- Publish
- Verify Release
- Use the Helper Script
- Common Failure Cases
Introduction
This guide documents a safe release flow for publishing a scoped package to npm. It focuses on repeatable commands and validation steps before and after release.
Quick Release Commands
Use this sequence when you want a fast, repeatable release checklist:
npm login
npm whoami
npm install
npm run build
npm test
npm pack --dry-run
npm version patch
npm publish --access public
npm view @technoapple/ga4 version
Replace npm version patch with npm version minor or npm version major when needed.
Confirm npm Account and Scope Access
Make sure you are logged in and have permission for the @technoapple scope.
npm login
npm whoami
Validate Package Metadata
Check these fields in package.json before release:
nameversionmaintypingslicense
Because this is a scoped package (@technoapple/ga4), publish it with public access.
Build and Test Before Publish
Run install, build, and tests first:
npm install
npm run build
npm test
Verify What Will Be Published
Preview the package contents:
npm pack --dry-run
Confirm only expected files are included.
Bump Version
Choose one based on the type of change:
npm version patch
npm version minor
npm version major
This updates the package version and creates a Git tag.
Publish
For first publish (or any scoped public publish), run:
npm publish --access public
If 2FA is enabled for npm, you may be prompted for an OTP.
Verify Release
Check the published version:
npm view @technoapple/ga4 version
Confirm the npm registry shows the new version.
Use the Helper Script
You can also use the helper script in package.json:
npm run deploy
This runs build and then publishes with public access. It is still recommended to run tests and npm pack --dry-run before using deploy.
Common Failure Cases
- You do not own the scope or package.
- Version already exists (bump the version first).
- Publishing to the wrong registry (check with
npm config get registry).
Following this order helps reduce publish-time surprises and makes releases easier to repeat.