wxml-transpiler
raw JSON → 1.0.5 verified Fri May 01 auth: no javascript
WXML template compiler for WeChat Mini Programs, version 1.0.5. It transpiles WXML files into JavaScript render functions, similar to wcc.exe and wcc. Designed for build tooling and automation.
Common errors
error Cannot find module 'wxml-transpiler' ↓
cause The package is not installed or is installed globally but used locally.
fix
Run npm install wxml-transpiler in the project root.
error require is not defined ↓
cause Code is running in an ESM context where require is not available.
fix
Use createRequire from 'module' or switch to CommonJS.
error wxmlCompile is not a function ↓
cause Incorrect import; the function is not exported as default.
fix
Use const { wxmlCompile } = require('wxml-transpiler');
Warnings
gotcha Only CommonJS imports are supported; ESM (import) will fail as the package has no default export. ↓
fix Use require() instead of import.
gotcha The file list paths must be absolute or relative to the current working directory; otherwise compilation fails silently. ↓
fix Use path.resolve() to ensure absolute paths.
gotcha The package does not include TypeScript type definitions; type checking will be disabled. ↓
fix Create a custom .d.ts file if needed.
gotcha The output is a single string of JavaScript code; there is no AST or source map support. ↓
fix None; designed for simple compilation.
Install
npm install wxml-transpiler yarn add wxml-transpiler pnpm add wxml-transpiler Imports
- wxmlCompile wrong
const compiler = require('wxml-transpiler'); compiler.wxmlCompile(...)correctconst { wxmlCompile } = require('wxml-transpiler') - default wrong
import compiler from 'wxml-transpiler'correctconst compiler = require('wxml-transpiler') - compile wrong
const compile = require('wxml-transpiler').compilecorrectconst { compile } = require('wxml-transpiler')
Quickstart
const { wxmlCompile } = require('wxml-transpiler');
const fileList = [
'./pages/index/index.wxml',
'./common/head.wxml',
'./common/foot.wxml'
];
const result = wxmlCompile(fileList);
console.log(result);