{"id":25944,"library":"miniprogram-compiler","title":"miniprogram-compiler","description":"Node.js wrapper for WeChat Mini Program official compilers (wcc for WXML, wcsc for WXSS). Version 0.2.3 is the latest stable release. It enables compiling .wxml and .wxss files into JavaScript functions that can render virtual DOM or CSS strings. Compared to alternatives like @vant/weapp or raw CLI tools, this package provides a programmatic API suitable for server-side rendering or testing. Release cadence is low; limited to basic compilation use. Only for Node.js (CJS only).","status":"active","version":"0.2.3","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install miniprogram-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add miniprogram-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add miniprogram-compiler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"The official wxml compiler from WeChat; this is a wrapper.","package":"wcc","optional":false},{"reason":"The official wxss compiler from WeChat; this is a wrapper.","package":"wcsc","optional":false}],"imports":[{"note":"Package is CJS-only; ES import will fail.","wrong":"import { wxmlToJs } from 'miniprogram-compiler';","symbol":"wxmlToJs","correct":"const { wxmlToJs } = require('miniprogram-compiler');"},{"note":"Also CJS-only. No default export.","wrong":"","symbol":"wxssToJs","correct":"const { wxssToJs } = require('miniprogram-compiler');"}],"quickstart":{"code":"const { wxmlToJs } = require('miniprogram-compiler');\nconst path = require('path');\n\nconst miniprogramProjectRoot = path.resolve('./test');\nconst compilerString = wxmlToJs(miniprogramProjectRoot);\nconst compiler = new Function('global', compilerString);\nconst $gwx = compiler({});\nconst generateFunc = $gwx('wxml/index.wxml');\nconst result = generateFunc({\n  message: 'Hello',\n  list: [1, 2, 3]\n});\nconsole.log(result);","lang":"javascript","description":"Compiles a .wxml file into a virtual DOM generator using the provided project root."},"warnings":[{"fix":"Use require() or configure bundler to handle CJS modules.","message":"Package is CJS-only; ES imports will fail.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use path.resolve() to provide an absolute path.","message":"The first argument to wxmlToJs and wxssToJs must be an absolute path to the mini program project root directory.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure the directory exists and contains valid project files.","message":"wxmlToJs and wxssToJs may throw if the project root does not exist or does not contain mini program files.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use new Function('global', compilerString) and then invoke with an object.","message":"The returned compiler string must be evaluated with a function constructor; not just required/imported.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Pass relative paths like 'pages/index/index.wxml'.","message":"The $gwx function expects file paths relative to the project root, not absolute paths.","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":"Use new Function('global', compilerString) to create a function.","cause":"Calling wxmlToJs result directly instead of wrapping in new Function.","error":"TypeError: compilerString is not a function"},{"fix":"Ensure the project root contains the expected files and that you called compiler({}) correctly.","cause":"The compiler evaluation didn't return a valid $gwx function (wrong project root or missing wxml files).","error":"TypeError: $gwx is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}