{"id":19303,"library":"babel-preset-jsdoc-to-assert","title":"babel-preset-jsdoc-to-assert","description":"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.","status":"active","version":"5.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/azu/babel-preset-jsdoc-to-assert","tags":["javascript","babel","preset","jsdoc","assert","test"],"install":[{"cmd":"npm install babel-preset-jsdoc-to-assert","lang":"bash","label":"npm"},{"cmd":"yarn add babel-preset-jsdoc-to-assert","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-preset-jsdoc-to-assert","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"core transformation logic","package":"babel-plugin-jsdoc-to-assert","optional":false},{"reason":"required peer dependency for Babel 7 preset","package":"@babel/core","optional":true}],"imports":[{"note":"Use as a preset name string in .babelrc or babel.config.js.","wrong":"require('babel-preset-jsdoc-to-assert') // wrong: should be a string in Babel config","symbol":"babel-preset-jsdoc-to-assert","correct":"module.exports = { presets: ['jsdoc-to-assert'] };"}],"quickstart":{"code":"// Install\nnpm install --save-dev babel-preset-jsdoc-to-assert @babel/core @babel/cli\n\n// .babelrc\n{\n  \"presets\": [\"jsdoc-to-assert\"]\n}\n\n// Input: src/example.js\n/** @param {number} n */\nfunction double(n) {\n  return n * 2;\n}\n\n// Run: npx babel src --out-dir lib\n// Output: lib/example.js\nfunction double(n) {\n  if (!(typeof n === 'number')) throw new Error(\"assertion failed: n is not a number\");\n  return n * 2;\n}","lang":"javascript","description":"Install preset and transform JSDoc type annotations to runtime assertions via Babel CLI."},"warnings":[{"fix":"Upgrade to Babel 7 and use preset 'jsdoc-to-assert'.","message":"v5.0.0 requires Babel 7.x; presets from v4.x are incompatible with Babel 7.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Review generated assertions; see plugin changelog for details.","message":"v4.0.0 updated babel-plugin-jsdoc-to-assert to 3.0.0 which may change assertion output.","severity":"breaking","affected_versions":">=4.0.0 <5.0.0"},{"fix":"Combine with other presets (e.g., @babel/preset-env) for full compilation.","message":"Preset only includes a single plugin; it does not configure any other Babel transformations.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use 'jsdoc-to-assert' in presets array.","message":"Preset name must be 'jsdoc-to-assert' in config; using full package name 'babel-preset-jsdoc-to-assert' may fail.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Set presets: ['jsdoc-to-assert'] in .babelrc or babel.config.js.","cause":"Using the preset as a require()d object instead of a string in Babel config.","error":"Error: Plugin/Preset files are not allowed to export objects, only functions."},{"fix":"Run npm install --save-dev babel-preset-jsdoc-to-assert and ensure Babel 7 is used.","cause":"Package not installed or incorrect Babel version (Babel 6 vs 7).","error":"Module not found: Can't resolve 'babel-preset-jsdoc-to-assert'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}