Publishing to npm and Semantic Versioning
Automate releases with changesets or semantic-release and publish scoped packages to the npm registry.
Publishing to npm and Semantic Versioning is a free React Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the React Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
npm publish --dry-run
Before publishing, always run npm publish --dry-run. This simulates the publish without actually uploading anything, showing you exactly which files would be included, their sizes, and the package tarball contents. It catches common mistakes like accidentally including source files or missing the dist directory.
Controlling Published Files
Control what gets published using the files field in package.json: "files": ["dist", "README.md"]. This whitelist approach is safer than .npmignore (which is a blacklist and can leak sensitive files if you forget to add them). Always include dist, type declarations, and documentation. Never include src, tests, or node_modules.
Semantic Versioning Basics
npm packages follow semantic versioning (semver): MAJOR.MINOR.PATCH. Increment MAJOR for breaking changes (removing props, changing API signatures). Increment MINOR for new backwards-compatible features (new components, new optional props). Increment PATCH for backwards-compatible bug fixes. Version 0.x.x is considered pre-stable where anything may break.
Pre-release Versions
Pre-release identifiers signal that a version is not production-ready: 1.0.0-alpha.1 for early experimental builds, 1.0.0-beta.2 for feature-complete but possibly buggy versions, and 1.0.0-rc.1 (release candidate) for versions ready for final testing. Publish pre-releases with npm publish --tag beta so they do not become the default install.
The changesets Tool
Changesets is the standard tool for managing package versioning and changelogs in component libraries. Workflow: contributors run yarn changeset add to record what changed and the change type (major/minor/patch). CI runs yarn changeset version to bump package versions. Publishing runs yarn changeset publish to push to npm.
Automatic CHANGELOG Generation
Changesets automatically generates and maintains CHANGELOG.md based on the changeset files committed by contributors. Each entry includes the version number, release date, and descriptions of changes. This creates a human-readable history of every version without requiring manual changelog maintenance.
semantic-release as an Alternative
semantic-release is a fully automated versioning tool that determines the next version from conventional commit messages (feat: → minor, fix: → patch, BREAKING CHANGE: → major). It bumps the version, generates the changelog, and publishes to npm — all triggered by CI on merge to main. Zero manual version management.
npm Access: Public vs Restricted
Unscoped packages (my-component) are always public. Scoped packages (@myorg/my-component) default to restricted (private) — publish them public with npm publish --access public. Restricted packages require an npm paid account or organization. Confirm access settings before your first publish.
npm Provenance
npm provenance links your published package to its specific git commit in a verifiable way. Enable it with npm publish --provenance in GitHub Actions. Consumers can verify that the package they installed was built from the exact source commit shown on the npm registry page. This significantly improves supply chain security.
Deprecating Old Versions
When a version has a critical bug or breaking change, deprecate it: npm deprecate your-package@1.2.3 "Security vulnerability, upgrade to 1.2.4". npm shows a deprecation warning to anyone installing that version. This does not remove the version (npm does not delete published versions by default) but alerts users to upgrade.
Scoped Package Naming
Scoped packages use the format @scope/package-name. The scope is typically your npm username or organization name. Scoped packages make it clear who maintains the package and prevent naming conflicts with unscoped packages. Use scoped packages for private packages and for open-source packages associated with your organization.
Semantic Versioning: Major vs Minor
According to semantic versioning, when should you increment the MAJOR version number?
Lesson Recap: Publishing and Versioning
Use npm publish --dry-run to preview and files field to control what is published. Semantic versioning: MAJOR for breaking changes, MINOR for new features, PATCH for fixes. Pre-releases use -alpha/-beta/-rc tags. Changesets automates versioning and CHANGELOG generation for collaborative libraries. semantic-release automates from conventional commits. Enable --provenance for supply chain security. Deprecate buggy versions with npm deprecate.
Frequently asked questions
Is the “Publishing to npm and Semantic Versioning” lesson free?
Yes — the full text of “Publishing to npm and Semantic Versioning” is free to read here on the web, and the React Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the React Academy course, upgrade to CoddyKit PRO.
What will I learn in “Publishing to npm and Semantic Versioning”?
Automate releases with changesets or semantic-release and publish scoped packages to the npm registry. You practise React Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start React Academy?
No prior experience is required. React Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Publishing to npm and Semantic Versioning” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this React Academy lesson?
Yes. Every React Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Bundling with Rollup and tsup for Libraries
- ESM and CJS Dual Package Output
- Peer Dependencies and Tree Shaking
- Publishing to npm and Semantic Versioning