Registry / devops / solc-js

solc-js

JSON →
library1.0.1jsnpmunverified

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.

npm install solc-js
INSTALL
IMPORT
SIG · SOLC-JS
S
solc-js
devopsjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import solcjs from 'solc-js'
✗ const solcjs = require('solc-js')
solc-js is ESM-only; CommonJS require will fail. Use dynamic import in Node.js if needed.
types
✓ import type { SolcJS, CompilerOutput } from 'solc-js'
✗ None
TypeScript types are exported but minimal; consider declaring own types for compiler output.
versions
✓ const { versions } = await import('solc-js')
✗ const { versions } = require('solc-js')
CommonJS require does not work; use dynamic import or ESM.
version2url
✓ const { version2url } = await import('solc-js')
✗ const version2url = solcjs.version2url
Named export, not a method on the default export.

Import solc-js, fetch available versions, load a specific compiler, and compile a simple Solidity contract.

import solcjs, { versions } from 'solc-js'; async function compile() { const allVersions = await versions(); console.log('Available releases:', allVersions.releases); const version = allVersions.releases[0] || 'v0.8.20-stable-2023.06.13'; const compiler = await solcjs(version); const source = ` pragma solidity ^0.8.0; contract HelloWorld { string public greeting = "Hello, World!"; } `; const output = await compiler(source); console.log('Compiled bytecode:', output.bytecode); } compile().catch(console.error);
Debug
Known issues
breakingsolc-js v1.0.0+ is ESM-only, breaking CommonJS require.
fix
Use ESM imports (`import solcjs from 'solc-js'`) or dynamic import in Node.js.
affects: >=1.0.0
deprecatedThe default export `solcjs(version)` now returns a compiler function, not a compiler object with `.version`.
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.
affects: >=1.0.0
gotchaWhen calling `solcjs()` without version, it fetches the latest release, which may be a nightly build.
fix
Always specify a version string to avoid unexpected compiler versions. Use `versions().releases[0]` for stable.
affects: all
gotchaUsing `solcjs` in Node.js is not recommended; it may be slower and have different behavior than the native `solc` package.
fix
For Node.js, use `solc` or `solc-native` instead.
affects: all
Errors
Common errors & fixes
require is not defined in ES module scope
Trying to use CommonJS require with solc-js, which is ESM-only in v1.0+.
fix
Switch to ESM imports: `import solcjs from 'solc-js';`
TypeError: solcjs is not a function
Using `require('solc-js')` without .default (CommonJS interop) with older bundlers.
fix
Use `const solcjs = require('solc-js').default;` or upgrade to ESM.
Uncaught TypeError: compiler is not a function
Calling `await solcjs(version)` and then calling `compiler(source)` on the result, but `solcjs` itself is the compiler (no need to call twice).
fix
Use `const compiler = await solcjs(version); const output = await compiler(source);` correctly.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
solc-resolveroptionalRecommended for automatic import resolution when compiling projects with external file imports.
Agent activity
6 hits · last 30 days
node
6
Resources
solc-js — npm install solc-js · libregistry