Legacy CommonJS YAML Parser
The `yamlparser` package is an extremely old and unmaintained JavaScript YAML parser, last published in May 2013 with its only version being 0.0.2. It was created as a CommonJS port of an earlier client-side JavaScript YAML parser and aims to handle 'simply structured YAML files' rather than fully implementing the YAML specification. The package's GitHub repository was archived in December 2022, officially marking it as read-only and abandoned. Due to its age, lack of updates, and limited feature set, it is not suitable for modern applications. Users requiring YAML parsing functionality should consider actively maintained alternatives like `js-yaml` or `yaml` that support current YAML specifications and modern JavaScript environments (ESM).
Common errors
-
Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported. Instead change the require of ... to a dynamic import() call.
cause Attempting to `require()` an ES Module or using `import` to load this CommonJS package in an ES Module context.fixThis package is CommonJS-only. Ensure your project is configured for CommonJS or use a dynamic `import()` if bridging CJS and ESM. However, the fundamental fix is to migrate to a modern YAML parser that supports ESM. -
TypeError: yamlparser.parse is not a function
cause The specific API for `yamlparser` is not officially documented. While `parse` is a common method for parsers, the module might export its parsing functionality differently (e.g., directly as a function `require('yamlparser')(yamlString)` or with a different method name).fixDue to the lack of documentation, you would typically need to inspect the source code to determine the correct function to call. However, the recommended fix is to switch to a well-documented and maintained YAML parsing library.
Warnings
- breaking The `yamlparser` package is entirely abandoned. Its GitHub repository was archived in December 2022, and it has not been updated since its initial release in 2013. Using this package introduces significant security vulnerabilities due to unpatched issues and lack of maintenance.
- gotcha This package is strictly CommonJS (CJS) and does not support ES Modules (ESM). Attempting to import it using `import` statements in an ESM project will result in a runtime error.
- gotcha The package documentation is explicitly marked as 'ToDo' on npm, meaning there is no official API documentation. The exact methods and their behavior (e.g., `parse`, `load`, error handling) are not specified and must be inferred or found through source code analysis.
- gotcha The package explicitly states it 'does not intend to implement all the aspects formalized in the YAML specs,' focusing only on 'simply structured YAML files.' Complex YAML features (e.g., anchors, tags, specific data types) may not be supported or may be parsed incorrectly.
Install
-
npm install yamlparser -
yarn add yamlparser -
pnpm add yamlparser
Imports
- parse
import { parse } from 'yamlparser';const yamlparser = require('yamlparser'); const parsed = yamlparser.parse(yamlString);
Quickstart
const yamlparser = require('yamlparser');
const yamlString = `
name: John Doe
age: 30
cities:
- New York
- London
active: true
`;
try {
const data = yamlparser.parse(yamlString);
console.log('Parsed YAML:', data);
// Expected output: { name: 'John Doe', age: 30, cities: [ 'New York', 'London' ], active: true }
} catch (error) {
console.error('Failed to parse YAML:', error.message);
}
// Example with invalid YAML (may throw an error or produce unexpected results depending on implementation)
const invalidYamlString = `
key: value
another_key: indented_incorrectly
`;
try {
const invalidData = yamlparser.parse(invalidYamlString);
console.log('Parsed invalid YAML:', invalidData);
} catch (error) {
console.error('Failed to parse invalid YAML as expected:', error.message);
}