{"id":26412,"library":"solc-js","title":"solc-js","description":"solc-js v1.0.1 is a cross-browser JavaScript bindings for the Solidity compiler, using Emscripten-compiled solc binaries from the solc-bin repository. It is designed as a smaller and faster alternative to the solc package for browser-only environments, while solc or solc-native are recommended for Node.js. It provides an async API to fetch compiler versions, compile Solidity source code, and resolve imports. It has a moderate release cadence and is maintained as part of the ethereum-play project on GitHub.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/ethereum-play/solc-js","tags":["javascript","ethereum","solidity","compiler","browser","web","abi","bytecode"],"install":[{"cmd":"npm install solc-js","lang":"bash","label":"npm"},{"cmd":"yarn add solc-js","lang":"bash","label":"yarn"},{"cmd":"pnpm add solc-js","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Recommended for automatic import resolution when compiling projects with external file imports.","package":"solc-resolver","optional":true}],"imports":[{"note":"solc-js is ESM-only; CommonJS require will fail. Use dynamic import in Node.js if needed.","wrong":"const solcjs = require('solc-js')","symbol":"default","correct":"import solcjs from 'solc-js'"},{"note":"TypeScript types are exported but minimal; consider declaring own types for compiler output.","wrong":"None","symbol":"types","correct":"import type { SolcJS, CompilerOutput } from 'solc-js'"},{"note":"CommonJS require does not work; use dynamic import or ESM.","wrong":"const { versions } = require('solc-js')","symbol":"versions","correct":"const { versions } = await import('solc-js')"},{"note":"Named export, not a method on the default export.","wrong":"const version2url = solcjs.version2url","symbol":"version2url","correct":"const { version2url } = await import('solc-js')"}],"quickstart":{"code":"import solcjs, { versions } from 'solc-js';\n\nasync function compile() {\n  const allVersions = await versions();\n  console.log('Available releases:', allVersions.releases);\n  const version = allVersions.releases[0] || 'v0.8.20-stable-2023.06.13';\n  const compiler = await solcjs(version);\n  const source = `\n    pragma solidity ^0.8.0;\n    contract HelloWorld {\n      string public greeting = \"Hello, World!\";\n    }\n  `;\n  const output = await compiler(source);\n  console.log('Compiled bytecode:', output.bytecode);\n}\ncompile().catch(console.error);","lang":"typescript","description":"Import solc-js, fetch available versions, load a specific compiler, and compile a simple Solidity contract."},"warnings":[{"fix":"Use ESM imports (`import solcjs from 'solc-js'`) or dynamic import in Node.js.","message":"solc-js v1.0.0+ is ESM-only, breaking CommonJS require.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Access `.version` from the `solcjs` module itself: `const { version } = await solcjs(version);` is incorrect; use `const compiler = await solcjs(version);` and check compiler.version if needed.","message":"The default export `solcjs(version)` now returns a compiler function, not a compiler object with `.version`.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Always specify a version string to avoid unexpected compiler versions. Use `versions().releases[0]` for stable.","message":"When calling `solcjs()` without version, it fetches the latest release, which may be a nightly build.","severity":"gotcha","affected_versions":"all"},{"fix":"For Node.js, use `solc` or `solc-native` instead.","message":"Using `solcjs` in Node.js is not recommended; it may be slower and have different behavior than the native `solc` package.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Switch to ESM imports: `import solcjs from 'solc-js';`","cause":"Trying to use CommonJS require with solc-js, which is ESM-only in v1.0+.","error":"require is not defined in ES module scope"},{"fix":"Use `const solcjs = require('solc-js').default;` or upgrade to ESM.","cause":"Using `require('solc-js')` without .default (CommonJS interop) with older bundlers.","error":"TypeError: solcjs is not a function"},{"fix":"Use `const compiler = await solcjs(version); const output = await compiler(source);` correctly.","cause":"Calling `await solcjs(version)` and then calling `compiler(source)` on the result, but `solcjs` itself is the compiler (no need to call twice).","error":"Uncaught TypeError: compiler is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}