Registry /
devops / js-yaml-cloudformation-schema
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
CLOUDFORMATION_SCHEMA
✓ import { CLOUDFORMATION_SCHEMA } from 'js-yaml-cloudformation-schema'
✗ const CLOUDFORMATION_SCHEMA = require('js-yaml-cloudformation-schema')
This package is ESM-only. CommonJS require will not work. Use ES module import or dynamic import.
js-yaml (safeLoad)
✓ import yaml from 'js-yaml'; const data = yaml.safeLoad(source, { schema: CLOUDFORMATION_SCHEMA })
✗ const yaml = require('js-yaml'); const data = yaml.load(source)
Always pass the schema option. Without it, short-form tags like !Ref will not be parsed correctly. Use safeLoad (not load) for security.
js-yaml (safeDump)
✓ const yamlOutput = yaml.safeDump(data, { schema: CLOUDFORMATION_SCHEMA })
✗ const yamlOutput = yaml.safeDump(data)
Dumping also requires the schema option to preserve short-form syntax in the output.
Reads a CloudFormation YAML template, parses short-form intrinsics, and dumps back to YAML preserving syntax.
import fs from 'fs';
import yaml from 'js-yaml';
import { CLOUDFORMATION_SCHEMA } from 'js-yaml-cloudformation-schema';
const templatePath = process.env.TEMPLATE_PATH || 'template.yaml';
const templateBody = fs.readFileSync(templatePath, 'utf8');
const parsed = yaml.safeLoad(templateBody, { schema: CLOUDFORMATION_SCHEMA });
console.log('Parsed JSON:', JSON.stringify(parsed, null, 2));
const dumped = yaml.safeDump(parsed, { schema: CLOUDFORMATION_SCHEMA });
console.log('Dumped YAML:', dumped);
Debug
Known issues
breakingThis package is ESM-only (type: module in package.json). Using require() will throw an error.fixUse ES module import syntax (import) for this package. If you must use CommonJS, use dynamic import: const { CLOUDFORMATION_SCHEMA } = await import('js-yaml-cloudformation-schema'); affects: >=1.0.0
deprecatedjs-yaml's safeLoad and safeDump are deprecated in js-yaml v4. Use yaml.load and yaml.dump with schema option instead.fixUse yaml.load and yaml.dump from js-yaml v4, still passing schema: CLOUDFORMATION_SCHEMA.
affects: >=1.0.0 (js-yaml v4+)
gotchaThis schema only handles short-form intrinsic functions (e.g., !Ref, !Base64). Standard CloudFormation functions (Fn::Sub, etc.) are not supported in short form.fixUse the YAML short-form tags listed in the package's tags.json. For other functions, use the full Fn:: format.
affects: >=1.0.0
gotchaThe package has not been updated since initial release; it may not support newer js-yaml versions beyond v4.fixTest compatibility with your js-yaml version. If issues arise, consider pinning js-yaml to v3 or using a maintained alternative.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'js-yaml-cloudformation-schema' or its corresponding type declarations
The package is ESM-only and TypeScript may not resolve types correctly without configuration.
fixEnsure your tsconfig.json has 'moduleResolution': 'node' or 'bundler' and 'esModuleInterop': true. Add 'allowSyntheticDefaultImports': true if needed.
CLOUDFORMATION_SCHEMA is not defined / Property 'CLOUDFORMATION_SCHEMA' does not exist on type 'typeof import("js-yaml-cloudformation-schema")'
Using CommonJS require instead of ES import, or type definitions not loaded.
fixUse import { CLOUDFORMATION_SCHEMA } from 'js-yaml-cloudformation-schema'. If using require, use dynamic import: const { CLOUDFORMATION_SCHEMA } = await import('js-yaml-cloudformation-schema'); YAMLException: unknown tag !Ref (at line X, column Y)
The CLOUDFORMATION_SCHEMA was not passed to yaml.safeLoad.
fixPass the schema option: yaml.safeLoad(source, { schema: CLOUDFORMATION_SCHEMA }) Audit
Dependencies
js-yamlrequiredPeer dependency; the schema is designed to be used with js-yaml's safeLoad/safeDump methods.