{"id":25202,"library":"electrum-compiler","title":"electrum-compiler","description":"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.","status":"active","version":"1.9.0","language":"javascript","source_language":"en","source_url":"https://github.com/epsitec-sa/electrum-compiler","tags":["javascript"],"install":[{"cmd":"npm install electrum-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add electrum-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add electrum-compiler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for Electrum-enabled components.","package":"electrum","optional":false}],"imports":[{"note":"Compiler is a named export, not default.","wrong":"import Compiler from 'electrum-compiler'","symbol":"Compiler","correct":"import { Compiler } from 'electrum-compiler'"},{"note":"CommonJS destructuring required for named export.","wrong":"const Compiler = require('electrum-compiler')","symbol":"Compiler","correct":"const { Compiler } = require('electrum-compiler')"},{"note":"No function named compile; use Compiler class.","wrong":"import { compile } from 'electrum-compiler'","symbol":"Compiler","correct":"import { Compiler } from 'electrum-compiler'"}],"quickstart":{"code":"import { Compiler } from 'electrum-compiler';\n\nconst compiler = new Compiler();\n\n// Transform ES6 to ES5\nconst es5Source = compiler.transform('const greet = x => `Hello ${x}.`;');\nconsole.log(es5Source);\n\n// Build a React component with Electrum support\nconst componentSource = `\nclass extends React.Component {\n  render() {\n    return <Button>{text}</Button>;\n  }\n}`;\ncompiler.register('Button', Button); // Assume Button is a React component\ncompiler.register('text', 'Hello');\nconst output = compiler.build('MyComponent', componentSource);\nif (output.error) {\n  console.error(output.error);\n} else {\n  console.log('Component:', output.component);\n}\n\n// Evaluate an expression\nconst result = compiler.eval('2 + 3');\nconsole.log(result); // 5","lang":"javascript","description":"Demonstrates transforming ES6 to ES5, building an Electrum-enabled React component with registered symbols, and evaluating expressions."},"warnings":[{"fix":"When interpreting error line numbers, subtract 1 from the reported line.","message":"Error positions in build() are offset by one line due to prepended code.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider lazy-loading the compiler or using a server-side compilation approach for production.","message":"The compiler relies on a bundled babel-standalone; large bundle size may impact browser performance.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use unique keys when registering symbols, or create separate Compiler instances for isolation.","message":"The register() method stores items in a global-like catalog; multiple components may conflict if keys overlap.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use import { Compiler } from 'electrum-compiler'","cause":"Incorrect import: default import instead of named import.","error":"TypeError: Compiler is not a constructor"},{"fix":"Run npm install electrum@^4.3.0","cause":"Peer dependency electrum is not installed.","error":"Error: Cannot find module 'electrum'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}