Registry / testing / babel-preset-jsdoc-to-assert

babel-preset-jsdoc-to-assert

JSON →
library5.0.0jsnpmunverified

Babel preset that converts JSDoc type annotations into runtime assertion statements using babel-plugin-jsdoc-to-assert. Version 5.0.0 is current and requires Babel 7+. It is a thin wrapper around the core plugin, intended for easy integration via Babel presets. Release cadence is low; this package sees infrequent updates. Key differentiator: simplifies adding JSDoc-based runtime type assertions without manual checks.

npm install babel-preset-jsdoc-to-assert
INSTALL
IMPORT
SIG · BABEL-PRESET-JSDOC
B
babel-preset-jsdoc-to-assert
testingjavascriptv5.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

babel-preset-jsdoc-to-assert
module.exports = { presets: ['jsdoc-to-assert'] };
require('babel-preset-jsdoc-to-assert') // wrong: should be a string in Babel config
Use as a preset name string in .babelrc or babel.config.js.

Install preset and transform JSDoc type annotations to runtime assertions via Babel CLI.

// Install npm install --save-dev babel-preset-jsdoc-to-assert @babel/core @babel/cli // .babelrc { "presets": ["jsdoc-to-assert"] } // Input: src/example.js /** @param {number} n */ function double(n) { return n * 2; } // Run: npx babel src --out-dir lib // Output: lib/example.js function double(n) { if (!(typeof n === 'number')) throw new Error("assertion failed: n is not a number"); return n * 2; }
Debug
Known issues
breakingv5.0.0 requires Babel 7.x; presets from v4.x are incompatible with Babel 7.
fix
Upgrade to Babel 7 and use preset 'jsdoc-to-assert'.
affects: >=5.0.0
breakingv4.0.0 updated babel-plugin-jsdoc-to-assert to 3.0.0 which may change assertion output.
fix
Review generated assertions; see plugin changelog for details.
affects: >=4.0.0 <5.0.0
gotchaPreset only includes a single plugin; it does not configure any other Babel transformations.
fix
Combine with other presets (e.g., @babel/preset-env) for full compilation.
affects: >=1.0.0
gotchaPreset name must be 'jsdoc-to-assert' in config; using full package name 'babel-preset-jsdoc-to-assert' may fail.
fix
Use 'jsdoc-to-assert' in presets array.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Plugin/Preset files are not allowed to export objects, only functions.
Using the preset as a require()d object instead of a string in Babel config.
fix
Set presets: ['jsdoc-to-assert'] in .babelrc or babel.config.js.
Module not found: Can't resolve 'babel-preset-jsdoc-to-assert'
Package not installed or incorrect Babel version (Babel 6 vs 7).
fix
Run npm install --save-dev babel-preset-jsdoc-to-assert and ensure Babel 7 is used.
Upgrade
Version history
5.0.0latest on npm
Audit
Dependencies
babel-plugin-jsdoc-to-assertrequiredcore transformation logic
@babel/coreoptionalrequired peer dependency for Babel 7 preset
Agent activity
18 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
babel-preset-jsdoc-to-assert — npm install babel-preset-jsdoc-to-assert · libregistry