Registry / web-framework / electrum-compiler

electrum-compiler

JSON →
library1.9.0jsnpmunverified

Run-time compiler for Electrum-enabled React components, based on babel-standalone. Version 1.9.0 is the latest stable release; the package has had a low release cadence with infrequent updates. It provides a Compiler class capable of transforming JavaScript to ES5 and building React components from source code at runtime. Key differentiators include integration with the Electrum framework, support for registering external symbols, and a built-in eval for ES6/JSX. Note that it compiles synchronously in the browser and depends on Electrum v4.3.0 as a peer dependency.

npm install electrum-compiler
INSTALL
IMPORT
SIG · ELECTRUM-COMPILER
E
electrum-compiler
web-frameworkjavascriptv1.9.0
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.

Compiler
import { Compiler } from 'electrum-compiler'
import Compiler from 'electrum-compiler'
Compiler is a named export, not default.
Compiler
const { Compiler } = require('electrum-compiler')
const Compiler = require('electrum-compiler')
CommonJS destructuring required for named export.
Compiler
import { Compiler } from 'electrum-compiler'
import { compile } from 'electrum-compiler'
No function named compile; use Compiler class.

Demonstrates transforming ES6 to ES5, building an Electrum-enabled React component with registered symbols, and evaluating expressions.

import { Compiler } from 'electrum-compiler'; const compiler = new Compiler(); // Transform ES6 to ES5 const es5Source = compiler.transform('const greet = x => `Hello ${x}.`;'); console.log(es5Source); // Build a React component with Electrum support const componentSource = ` class extends React.Component { render() { return <Button>{text}</Button>; } }`; compiler.register('Button', Button); // Assume Button is a React component compiler.register('text', 'Hello'); const output = compiler.build('MyComponent', componentSource); if (output.error) { console.error(output.error); } else { console.log('Component:', output.component); } // Evaluate an expression const result = compiler.eval('2 + 3'); console.log(result); // 5
Debug
Known issues
gotchaError positions in build() are offset by one line due to prepended code.
fix
When interpreting error line numbers, subtract 1 from the reported line.
affects: >=1.0.0
gotchaThe compiler relies on a bundled babel-standalone; large bundle size may impact browser performance.
fix
Consider lazy-loading the compiler or using a server-side compilation approach for production.
affects: >=1.0.0
gotchaThe register() method stores items in a global-like catalog; multiple components may conflict if keys overlap.
fix
Use unique keys when registering symbols, or create separate Compiler instances for isolation.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Compiler is not a constructor
Incorrect import: default import instead of named import.
fix
Use import { Compiler } from 'electrum-compiler'
Error: Cannot find module 'electrum'
Peer dependency electrum is not installed.
fix
Run npm install electrum@^4.3.0
Upgrade
Version history
1.9.0latest on npm
Audit
Dependencies
electrumrequiredPeer dependency required for Electrum-enabled components.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
electrum-compiler — npm install electrum-compiler · libregistry