{"id":11459,"library":"node-version-compare","title":"Semantic Version Comparison Utility","description":"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.","status":"abandoned","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/leohihimax/node-version-compare","tags":["javascript","semver","version","compare"],"install":[{"cmd":"npm install node-version-compare","lang":"bash","label":"npm"},{"cmd":"yarn add node-version-compare","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-version-compare","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only.","symbol":"compare","correct":"const compare = require('node-version-compare');"},{"note":"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.","wrong":"import { compare } from 'node-version-compare';","symbol":"compare","correct":"import compare from 'node-version-compare';"}],"quickstart":{"code":"const compare = require('node-version-compare');\n\nconsole.log(compare('1.0.0', '1.0.1'));                     // Expected: -1\nconsole.log(compare('10.2.0-alpha.1', '10.2.0-alpha.1'));   // Expected: 0\nconsole.log(compare('10.2.0-beta', '10.2.0-alpha'));        // Expected: 1\nconsole.log(compare('3.1.1-1', '3.1.1-2'));                 // Expected: -1\nconsole.log(compare('1.2.3', '1.2.3-alpha'));               // Expected: 1 (stable is greater than pre-release)\nconsole.log(compare('1.0.0-rc.1', '1.0.0-rc.1.1'));         // Expected: -1","lang":"javascript","description":"Demonstrates basic semantic version comparison, showing how it handles different version parts and pre-release tags."},"warnings":[{"fix":"Consider using actively maintained alternatives like `version-compare` or `compare-versions` for robust semver comparison.","message":"The 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.","severity":"breaking","affected_versions":">=1.0.3"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Thoroughly test with your specific version strings or migrate to a more current, actively maintained semver library.","message":"Given 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"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.","error":"ERR_REQUIRE_ESM"},{"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.","cause":"Incorrectly importing the default export as a named export (e.g., `import { compare } from 'pkg';`) or attempting to call `require('pkg').compare`.","error":"TypeError: compare is not a function"}],"ecosystem":"npm"}