Spectral CLI Bundle
raw JSON → 1.0.8 verified Sat Apr 25 auth: no javascript
Bundled version of @stoplight/spectral-cli v1.0.8 providing a self-contained executable for API linting with Spectral, pre-packaged to avoid external dependencies. Requires Node.js >=20. Released under MIT license, updated infrequently (last release 2023). Differentiator: single-file distribution, no need for npm install or separate Spectral CLI setup.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/spectral-cli-bundle/index.js from /path/to/file.js not supported. ↓
cause Use of CommonJS require() with an ESM-only package.
fix
Use import instead: import { spectral } from 'spectral-cli-bundle'; or use dynamic import()
error TypeError: Cannot read properties of undefined (reading 'run') ↓
cause Imported from wrong package (e.g., '@stoplight/spectral-cli') instead of 'spectral-cli-bundle'.
fix
Change import source to 'spectral-cli-bundle'.
Warnings
breaking package requires Node.js >=20, older versions will fail to run ↓
fix Upgrade Node.js to version 20 or later.
gotcha import must be from 'spectral-cli-bundle' not '@stoplight/spectral-cli' ↓
fix Replace all imports from '@stoplight/spectral-cli' with 'spectral-cli-bundle'.
gotcha CommonJS require() is not supported; use ESM import ↓
fix Convert require() to import statement or use dynamic import() if needed.
Install
npm install spectral-cli-bundle yarn add spectral-cli-bundle pnpm add spectral-cli-bundle Imports
- spectral wrong
const spectral = require('spectral-cli-bundle')correctimport { spectral } from 'spectral-cli-bundle' - Spectral wrong
import { Spectral } from '@stoplight/spectral-cli'correctimport { Spectral } from 'spectral-cli-bundle'
Quickstart
import { spectral } from 'spectral-cli-bundle';
const result = await spectral.run({
args: ['lint', '--format', 'stylish', 'api.yaml'],
stdout: process.stdout,
stderr: process.stderr
});
console.log('Exit code:', result.exitCode);