{"id":20634,"library":"typhonjs-escomplex","title":"typhonjs-escomplex","description":"Next generation JavaScript and TypeScript complexity reporting module powered by the Babel parser. Version 0.1.0 is current, but this project appears to be in an early/alpha state with active development. It computes cyclomatic complexity, Halstead metrics, maintainability index, and dependency analysis. Unlike older complexity tools (e.g., escomplex), this uses the full Babel parser with all plugins enabled, supporting modern JS and TS syntax out of the box. The library is designed as a modular shim; separate sub-packages handle AST processing independently. Note that breaking report format changes occurred in 0.1.0.","status":"active","version":"0.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/typhonjs-node-escomplex/typhonjs-escomplex","tags":["javascript","typhonjs","escomplex","complexity","simplicity","cyclomatic","halstead","maintainability","dependencies"],"install":[{"cmd":"npm install typhonjs-escomplex","lang":"bash","label":"npm"},{"cmd":"yarn add typhonjs-escomplex","lang":"bash","label":"yarn"},{"cmd":"pnpm add typhonjs-escomplex","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"All-in-one Babel parser with all plugins enabled to produce the AST for complexity analysis.","package":"@babel/parser","optional":false}],"imports":[{"note":"Use default import for ESM. The module exports a single default object.","wrong":"import { escomplex } from 'typhonjs-escomplex';","symbol":"escomplex","correct":"import escomplex from 'typhonjs-escomplex';"},{"note":"CommonJS require returns the default export directly. Named destructuring is incorrect.","wrong":"const { escomplex } = require('typhonjs-escomplex');","symbol":"escomplex","correct":"const escomplex = require('typhonjs-escomplex');"},{"note":"Pass a string of source code, not a file path. For file analysis, read the file first.","wrong":"escomplex.analyzeModule('source');","symbol":"analyzeModule","correct":"escomplex.analyzeModule(source);"}],"quickstart":{"code":"import escomplex from 'typhonjs-escomplex';\nimport { readFileSync } from 'fs';\n\nconst source = readFileSync('./example.js', 'utf8');\nconst report = escomplex.analyzeModule(source);\n\nconsole.log(JSON.stringify(report, null, 2));","lang":"javascript","description":"Analyze a JavaScript file for complexity metrics including cyclomatic, Halstead, and maintainability index."},"warnings":[{"fix":"Review the 0.1.0 update guide at https://github.com/typhonjs-node-escomplex/typhonjs-escomplex/wiki/0.1.0-update-guide and adjust any consumers that parse the report structure.","message":"Report format changed significantly in version 0.1.0.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"If you need fine-grained control, use @babel/parser + typhonjs-escomplex-* modules directly.","message":"This package is a shim over @babel/parser. For direct AST processing, use the individual sub-packages in the typhonjs-node-escomplex organization.","severity":"deprecated","affected_versions":"*"},{"fix":"Use fs.readFileSync to read the file content before passing it.","message":"The analyzeModule function expects source code as a string, not a file path.","severity":"gotcha","affected_versions":"*"},{"fix":"Use a bundler like webpack or rollup if you need to run in the browser.","message":"Only CommonJS and ES module inputs are supported; no UMD or browser build provided.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use `import escomplex from 'typhonjs-escomplex'` or `const escomplex = require('typhonjs-escomplex')`.","cause":"Importing the module incorrectly (e.g., named import instead of default).","error":"TypeError: escomplex.analyzeModule is not a function"},{"fix":"Read the file content first: `const source = fs.readFileSync(filePath, 'utf8');` then pass `source`.","cause":"Passing a file path string instead of source code content to analyzeModule.","error":"SyntaxError: Unexpected token (1:1) while parsing"},{"fix":"Run `npm install @babel/parser` (or yarn add) to install the peer dependency.","cause":"Missing @babel/parser peer dependency.","error":"Error: Could not find module: @babel/parser"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}