{"id":25974,"library":"nativejs-compiler","title":"nativejs-compiler","description":"nativejs-compiler (also known as hardware.js) is a JavaScript/TypeScript to C transpiler that converts JS/TS code into readable C89 code for low-power microcontrollers and IoT devices. Current version 2.0.0 (released July 2024) supports approximately 50% of ES3 syntax, targeting environments with very limited memory (512 bytes to 120KB RAM). Key differentiators include generating minimal, readable C code without unnecessary overhead, and employing escape analysis for memory management. It supports basic ES3 features like var, if-else, loops, functions, arrays, strings, and some built-in objects, but notably lacks support for float numbers, `this`, `new`, and `typeof`. Releases are occasional, focused on incremental feature coverage. Compared to other JS-to-C transpilers, it prioritizes output readability and small footprint over full language support.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"git://github.com/brunobasto/hardware.js","tags":["javascript","typescript"],"install":[{"cmd":"npm install nativejs-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add nativejs-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add nativejs-compiler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for parsing TypeScript source files and generating C code from TS input","package":"typescript","optional":true}],"imports":[{"note":"ESM-only since v2.0.0; CommonJS require will throw.","wrong":"const transpile = require('nativejs-compiler').transpile","symbol":"transpile","correct":"import { transpile } from 'nativejs-compiler'"},{"note":"`compile` is a named export, not default. The default export is not available.","wrong":"import compile from 'nativejs-compiler'","symbol":"compile","correct":"import { compile } from 'nativejs-compiler'"},{"note":"CompilerConfig is a TypeScript type, not a runtime value. Use `import type` to avoid runtime errors.","wrong":"import { CompilerConfig } from 'nativejs-compiler'","symbol":"CompilerConfig","correct":"import type { CompilerConfig } from 'nativejs-compiler'"}],"quickstart":{"code":"import { transpile } from 'nativejs-compiler';\nconst jsCode = `console.log(\"Hello world!\");`;\nconst cCode = transpile(jsCode);\nconsole.log(cCode);\n// Output:\n// #include <stdio.h>\n// int main() {\n//     printf(\"Hello world!\\n\");\n//     return 0;\n// }","lang":"typescript","description":"Transpiles a simple JavaScript 'Hello world' console.log to C code using the transpile function."},"warnings":[{"fix":"Use import syntax instead of require().","message":"ESM-only since v2.0.0: The package no longer supports CommonJS require() syntax.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Replace transpile() with compile().","message":"The `transpile` function is deprecated in favor of `compile`; `transpile` may be removed in v3.0.0.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Use integer values only, or check if float support is added in future versions.","message":"Float numbers are not supported; using them will cause compile-time errors or incorrect output.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Avoid using `this` or rewrite code to pass context explicitly.","message":"The `this` keyword is not supported; transpiling code that relies on `this` will fail.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Refer to COVERAGE.md in the GitHub repo for the current list of supported features.","message":"Only about 50% of ES3 features are implemented; using unsupported syntax will cause transpilation errors.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `npm install nativejs-compiler` and ensure the package name is 'nativejs-compiler'.","cause":"Package is not installed or wrong package name used.","error":"Error: Cannot find module 'nativejs-compiler'"},{"fix":"Use `import { transpile } from 'nativejs-compiler'` instead of `const { transpile } = require('nativejs-compiler')`.","cause":"Using CommonJS require instead of ESM import.","error":"TypeError: nativejs_compiler_1.transpile is not a function"},{"fix":"Remove usage of `this` or refactor code to use explicit parameters.","cause":"The `this` keyword is not supported by the transpiler.","error":"Unsupported feature: This expression (this)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}