{"id":18811,"library":"solidity-parser","title":"solidity-parser","description":"PEG.js-based Solidity parser for JavaScript. Current stable version is 0.4.0, released as pre-alpha software. Provides parse() and parseFile() functions to convert Solidity source code into a structured JSON AST, with an optional 'imports' mode to extract imported file paths. Intended for tooling that needs to analyze or transform Solidity code without relying on heavy preprocessors. The AST structure is unstable and incomplete, and the parser may silently skip unsupported Solidity constructs. Not recommended for production use.","status":"deprecated","version":"0.4.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install solidity-parser","lang":"bash","label":"npm"},{"cmd":"yarn add solidity-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add solidity-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package does not provide ESM exports; use CommonJS require.","wrong":"import SolidityParser from 'solidity-parser';","symbol":"default","correct":"const SolidityParser = require('solidity-parser');"},{"note":"parse() accepts a string and an optional options object (not well documented).","wrong":"SolidityParser.parse(code, {});","symbol":"parse","correct":"SolidityParser.parse(code);"},{"note":"Second argument can be 'imports' to extract imported files; 'ast' is the default.","wrong":"SolidityParser.parseFile('./path/to/file.sol', 'ast');","symbol":"parseFile","correct":"SolidityParser.parseFile('./path/to/file.sol');"}],"quickstart":{"code":"const SolidityParser = require('solidity-parser');\n\nconst solidityCode = `\ncontract Test {\n  uint256 public value;\n}\n`;\n\nconst ast = SolidityParser.parse(solidityCode);\nconsole.log(JSON.stringify(ast, null, 2));\n\n// Extract imports from a file\nconst imports = SolidityParser.parseFile('./path/to/file.sol', 'imports');\nconsole.log(imports);","lang":"javascript","description":"Shows basic parse and parseFile usage with CommonJS require."},"warnings":[{"fix":"Do not rely on specific AST shapes; always test after upgrading.","message":"The AST structure is unstable and changes between versions.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Consider using @solidity-parser/parser or other alternatives.","message":"This package is in pre-alpha and no longer actively maintained.","severity":"deprecated","affected_versions":">=0.4.0"},{"fix":"Validate parsed output for completeness; use a more robust parser for production.","message":"The parser silently ignores unsupported Solidity constructs.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Upgrade to a parser built on a modern parser generator.","message":"PEG.js dependency is outdated and may cause security vulnerabilities.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Ensure file exists before calling parseFile.","message":"parseFile requires the file to exist and be readable; no error handling for missing files.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Inspect the actual returned JSON to understand the structure.","message":"Output format may vary; documentation examples may not match actual output.","severity":"gotcha","affected_versions":">=0.4.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install' in the project directory, or install pegjs globally with 'npm install -g pegjs'.","cause":"Missing pegjs dependency when using package directly from GitHub or without proper install.","error":"Error: Cannot find module 'pegjs'"},{"fix":"Simplify or update the Solidity code to match older syntax; consider using a more modern parser like @solidity-parser/parser.","cause":"Solidity code contains constructs not supported by the parser (e.g., newer Solidity syntax).","error":"SyntaxError: Unexpected token"},{"fix":"Use const SolidityParser = require('solidity-parser'); instead of import.","cause":"Using ES6 import style instead of CommonJS require.","error":"TypeError: SolidityParser.parse is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}