Smartface Transpiler
raw JSON → 6.9.17-beta.5 verified Fri May 01 auth: no javascript
Transpiles JavaScript/TypeScript code for Smartface platform, enabling cross-platform mobile app development. Current stable version is 6.9.17-beta.5. This package is central to Smartface's build pipeline, converting standard JS/TS to Smartface-compatible code with platform-specific polyfills and module resolution. It differentiates by tightly integrating with Smartface's runtime and providing custom AST transformations. Release cadence is irregular with beta versions for new features.
Common errors
error TypeError: transpile is not a function ↓
cause Importing incorrectly (e.g., using require instead of ES import).
fix
Use import { transpile } from 'smartface-transpiler'; or import transpile from 'smartface-transpiler'; if using default export.
error Error: No platform specified ↓
cause Missing required 'platform' option in transpile call.
fix
Add platform: 'android' or 'iosx' to options object.
error SyntaxError: Unexpected token 'export' ↓
cause sourceType is set to 'script' but code contains ES module syntax.
fix
Set sourceType: 'module' in options for ES module code.
error Module not found: 'smartface-transpiler' ↓
cause Package not installed or not in node_modules.
fix
Run npm install smartface-transpiler --save or yarn add smartface-transpiler.
Warnings
breaking In v6, the transpile function changed from a synchronous to an asynchronous API. ↓
fix Use async/await or .then() when calling transpile.
deprecated Use of 'options.platform' with value 'ios' is deprecated; use 'iosx' instead. ↓
fix Replace 'ios' with 'iosx' in platform option.
gotcha The transpiler expects source type 'module' for ES module code; using 'script' will cause syntax errors on imports. ↓
fix Set sourceType to 'module' when transpiling ES modules.
gotcha TypeScript support requires additional plugins; transpiler alone does not strip types. ↓
fix Use the Smartface TypeScript plugin or preprocess with tsc.
breaking In v6.9, the output code format changed: all functions are now wrapped in IIFEs. ↓
fix Review generated code for compatibility if relying on global function declarations.
Install
npm install smartface-transpiler yarn add smartface-transpiler pnpm add smartface-transpiler Imports
- transpile wrong
const transpile = require('smartface-transpiler').transpilecorrectimport { transpile } from 'smartface-transpiler' - TranspileOptions wrong
import { TranspileOptions } from 'smartface-transpiler'correctimport type { TranspileOptions } from 'smartface-transpiler' - default wrong
import { default as transpile } from 'smartface-transpiler'correctimport transpile from 'smartface-transpiler'
Quickstart
import { transpile } from 'smartface-transpiler';
const sourceCode = `
const x = 1;
console.log(x);
`;
const result = transpile(sourceCode, {
platform: 'android',
moduleType: 'commonjs',
sourceType: 'script',
});
console.log(result.code);
console.log(result.map);