RAML 1.0 JavaScript Parser
The `fork-raml-1-parser` package is a JavaScript parser for RAML 0.8 and 1.0 API specifications. It reached its end-of-life and is officially deprecated as of its latest stable version, 1.1.68. Development on this package has ceased, with the recommendation to migrate to `@raml-org/webapi-parser` for ongoing support, security updates, and new features. While it ships with TypeScript types, providing better integration in typed environments, its primary quickstart examples and usage patterns often leverage CommonJS `require` syntax. Its release cadence was irregular towards its deprecation, primarily focusing on critical dependency and security fixes rather than new RAML specification features. A key differentiator was its ability to directly interpret RAML specification structures and produce a high-level Abstract Syntax Tree (AST), unlike generic YAML/JSON parsers.
Common errors
-
Error: Cannot find module 'raml-1-parser'
cause The package was not installed, or there's a path resolution issue in your environment.fixEnsure the package is installed using `npm install raml-1-parser` or `yarn add raml-1-parser`. For new projects, consider installing and using `@raml-org/webapi-parser` instead. -
TypeError: raml.load is not a function
cause Incorrect import of the `raml` object, or an outdated version of the package where the `load` method might be structured differently.fixVerify your import statement: `const raml = require('raml-1-parser');` for CommonJS or `import * as raml from 'raml-1-parser';` for ESM/TypeScript. Ensure you are using a consistent and reasonably recent version (e.g., >=1.1.50 if not migrating). -
Node 4.x or older compatibility errors (e.g., syntax errors with ES6 features)
cause Using a `raml-1-parser` version that dropped support for Node.js 4.x on an unsupported Node.js runtime.fixUpgrade your Node.js runtime to version 6 or higher. `raml-1-parser@1.1.51` and later explicitly require Node.js >=6.
Warnings
- breaking This package is officially deprecated. The RAML organization recommends migrating to `@raml-org/webapi-parser` for all new development and ongoing maintenance. No further feature development or active support is expected for `raml-1-parser`.
- breaking Node.js 4 support was dropped with version 1.1.51. Users on older Node.js runtimes will experience errors or require specific older versions of the parser.
- gotcha Versions prior to 1.1.59 had a security vulnerability related to the `serialize-javascript` dependency. While fixed in later `raml-1-parser` versions, older deployments might be at risk.
- gotcha Version 1.1.54 was a broken npm release and should be avoided. Installing or deploying this specific version will likely lead to operational failures.
Install
-
npm install fork-raml-1-parser -
yarn add fork-raml-1-parser -
pnpm add fork-raml-1-parser
Imports
- raml
import raml from 'raml-1-parser';
import * as raml from 'raml-1-parser';
- raml
const raml = require('raml-1-parser'); - webapi-parser
import { RamlParser } from '@raml-org/webapi-parser';
Quickstart
const raml = require("raml-1-parser");
const fs = require('fs');
const path = require('path');
// Create a dummy RAML file for the example
const ramlFileName = path.join(__dirname, 'my-api.raml');
const ramlContent = `#%RAML 1.0\ntitle: My Example API\nversion: v1\nbaseUri: https://api.example.com`;
fs.writeFileSync(ramlFileName, ramlContent);
console.log(`Parsing RAML file: ${ramlFileName}`);
try {
// The 'load' method can often work synchronously for local files.
const apiJSON = raml.load(ramlFileName);
console.log("Parsed RAML API JSON:");
console.log(JSON.stringify(apiJSON, null, 2));
} catch (error) {
console.error("Error parsing RAML file:", error);
}
// Clean up the dummy file
fs.unlinkSync(ramlFileName);