{"id":26414,"library":"solc","title":"solc-js","description":"JavaScript bindings for the Solidity compiler (solc), providing a high-level and low-level API to compile Solidity smart contracts to EVM bytecode. The current stable version is 0.8.35, following the Solidity compiler releases closely. It uses Emscripten-compiled Solidity binaries from solc-bin, supporting all compiler features via the Standard JSON interface. Key differentiators: it's the official JavaScript wrapper for Solidity, enabling dynamic compilation in Node.js and browser environments without a native binary. The package ships TypeScript types and supports both CommonJS and ESM modules (ESM requires Node >=12).","status":"active","version":"0.8.35","language":"javascript","source_language":"en","source_url":"https://github.com/ethereum/solc-js","tags":["javascript","ethereum","solidity","compiler","typescript"],"install":[{"cmd":"npm install solc","lang":"bash","label":"npm"},{"cmd":"yarn add solc","lang":"bash","label":"yarn"},{"cmd":"pnpm add solc","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core package; no external runtime dependencies beyond the compiler binary loaded from disk or network.","package":"solc","optional":false}],"imports":[{"note":"ESM named import available since v0.8.11; CJS still works but TypeScript prefers named import for type safety.","wrong":"const solc = require('solc'); solc.compile(...)","symbol":"compile","correct":"import { compile } from 'solc'"},{"note":"Default export is the main module but TypeScript may need allowSyntheticDefaultImports or esModuleInterop. Prefer named imports.","wrong":"import * as solc from 'solc'","symbol":"default","correct":"import solc from 'solc'"},{"note":"Only available via named import; used for low-level API with callback imports.","wrong":"","symbol":"compileCallback","correct":"import { compileCallback } from 'solc'"},{"note":"Exported as a function that returns the compiler version string; CJS require() also works.","wrong":"const solc = require('solc'); console.log(solc.version)","symbol":"version","correct":"import { version } from 'solc'"}],"quickstart":{"code":"import { compile } from 'solc';\n\nconst input = {\n  language: 'Solidity',\n  sources: {\n    'test.sol': {\n      content: 'contract C { function f() public { } }'\n    }\n  },\n  settings: {\n    outputSelection: {\n      '*': {\n        '*': ['evm.bytecode.object']\n      }\n    }\n  }\n};\n\nconst output = JSON.parse(compile(JSON.stringify(input)));\nconsole.log(output.contracts['test.sol'].C.evm.bytecode.object);","lang":"typescript","description":"Compiles a simple Solidity contract using the high-level API with Standard JSON input."},"warnings":[{"fix":"Wrap compile() call with JSON.parse() to get the output object.","message":"Breaking change in v0.8.11: compile() now returns JSON string instead of object. Wrap with JSON.parse.","severity":"breaking","affected_versions":">=0.8.11"},{"fix":"Update to use the object-based callback parameter: compile(input, { import: myImportFn }).","message":"Legacy callback-based API removed in v0.8.0. Use compile(input, { import: ... }) object syntax.","severity":"deprecated","affected_versions":"<0.8.0"},{"fix":"Pre-fetch all dependencies synchronously or use a synchronous file reader.","message":"The import callback must be synchronous. Async callbacks will cause undefined behavior.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade Node.js to >=10 (preferably >=12 for ESM).","message":"Version 0.6.0 dropped support for Node <6. Node 12+ required for ESM support.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Use native solc binary for full feature set or rely on solc-js CLI for simple compilation.","message":"solcjs CLI is not compatible with native solc CLI. It lacks some features.","severity":"deprecated","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure input is a non-empty JSON string with 'language', 'sources', and 'settings' fields.","cause":"compile() called without arguments or with invalid input.","error":"Error: No input specified"},{"fix":"Use import { compile } from 'solc' instead of import solc from 'solc'.","cause":"Import style mismatch (e.g., using default import when only named export exists).","error":"TypeError: solc.compile is not a function"},{"fix":"Run 'npm install solc' and ensure Node.js version >=12 for ESM or use CommonJS require.","cause":"Package not installed or ESM resolution issue (package not in node_modules).","error":"Module not found: Can't resolve 'solc'"},{"fix":"Use solc.compile() directly (it always was a function) or upgrade to >=0.8.11 and use named export.","cause":"Older solc versions (pre-0.8.11) had different export shape.","error":"solc.compile is not a function (when using require)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}