Registry / serialization / node-version-compare

node-version-compare

JSON →
library1.0.3jsnpmunverified

This package provides a lightweight utility function for comparing two semantic version strings, adhering to the semver specification. It evaluates major, minor, patch, and pre-release identifiers, returning -1 if the first version is less than the second, 0 if they are equal, and 1 if the first is greater. The current stable version is 1.0.3, which was last published over six years ago (as of 2026), indicating that the project is largely abandoned and no longer receives active maintenance or updates. Its key differentiator is its singular focus on version comparison without supporting more complex features like version ranges. Due to its age and lack of updates, it exclusively uses the CommonJS module format. Newer projects or those requiring ESM compatibility, TypeScript support, or active development should consider more modern alternatives.

npm install node-version-compare
INSTALL
IMPORT
SIG · NODE-VERSION-COMPA
N
node-version-compare
serializationjavascriptv1.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compare
const compare = require('node-version-compare');
This package is CommonJS-only.
compare
import compare from 'node-version-compare';
import { compare } from 'node-version-compare';
While Node.js supports ESM, this package is CommonJS-only and exports a default function. Direct ESM import might work with bundlers but fails in pure Node.js ESM projects.

Demonstrates basic semantic version comparison, showing how it handles different version parts and pre-release tags.

const compare = require('node-version-compare'); console.log(compare('1.0.0', '1.0.1')); // Expected: -1 console.log(compare('10.2.0-alpha.1', '10.2.0-alpha.1')); // Expected: 0 console.log(compare('10.2.0-beta', '10.2.0-alpha')); // Expected: 1 console.log(compare('3.1.1-1', '3.1.1-2')); // Expected: -1 console.log(compare('1.2.3', '1.2.3-alpha')); // Expected: 1 (stable is greater than pre-release) console.log(compare('1.0.0-rc.1', '1.0.0-rc.1.1')); // Expected: -1
Debug
Known issues
breakingThe package is effectively abandoned, with its last publish over six years ago. This means no new features, bug fixes, or security patches will be released.
fix
Consider using actively maintained alternatives like `version-compare` or `compare-versions` for robust semver comparison.
affects: >=1.0.3
gotchaThis library is CommonJS (CJS) only. Attempting to use `import` syntax in a pure ESM Node.js environment will result in an error unless a bundler handles the CJS-to-ESM conversion.
fix
For CommonJS projects, use `const compare = require('node-version-compare');`. For ESM projects, a wrapper or a different library might be necessary, or configure your bundler to handle CJS imports.
affects: >=1.0.0
gotchaThe package does not ship with TypeScript type definitions, leading to potential type-related issues or requiring manual declaration files (`.d.ts`) when used in TypeScript projects.
fix
Install `@types/node-version-compare` if available (unlikely for an abandoned package) or create a `declare module 'node-version-compare';` shim or `node-version-compare.d.ts` file with appropriate function signatures.
affects: >=1.0.0
gotchaGiven its age, the library may not fully conform to the latest semver specification updates or might have undiscovered edge case parsing bugs that will not be addressed.
fix
Thoroughly test with your specific version strings or migrate to a more current, actively maintained semver library.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to `require()` an ESM module in a CommonJS context, or more commonly, trying to `import` this CJS-only package in a Node.js project configured for ESM without proper interoperability handling.
fix
Ensure your Node.js project is configured for CommonJS, or use a bundler that transpiles CJS modules for ESM consumption. For direct Node.js ESM, this package is not compatible.
TypeError: compare is not a function
Incorrectly importing the default export as a named export (e.g., `import { compare } from 'pkg';`) or attempting to call `require('pkg').compare`.
fix
The package exports a single function as its default. In CommonJS, use `const compare = require('node-version-compare');`. If using ESM with a bundler, `import compare from 'node-version-compare';` is the correct pattern.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources