babel-preset-remax
raw JSON → 2.15.14 verified Sat Apr 25 auth: no javascript
Babel preset for Remax, a framework for building mini-programs using React. Current stable version is 2.15.14, with regular releases on GitHub. This preset configures @babel/preset-react, @babel/preset-typescript, and plugins for decorators and class properties, tailored for Remax apps. It differs from generic React presets by providing options to control React runtime, TypeScript namespace support, and legacy decorator syntax, ensuring compatibility with mini-program environments.
Common errors
error Error: [BABEL] unknown option: .throw-if-namespace ↓
cause Invalid option name; correct key is 'throw-if-namespace' (with quotes) in Babel config.
fix
Use 'throw-if-namespace' as a string key in object: { 'throw-if-namespace': false }.
error TypeError: Cannot read property 'call' of undefined ↓
cause Decorator plugin not loaded or misconfigured, often due to missing 'decorators.legacy' option.
fix
Add 'decorators: { legacy: true }' to preset options.
error Module not found: Can't resolve 'babel-preset-remax' ↓
cause Package not installed or incorrect import path in Babel config.
fix
Install with
npm install --save-dev babel-preset-remax and use 'remax' as preset name. Warnings
deprecated The 'throw-if-namespace' option is deprecated in recent React presets; use 'runtime: 'automatic'' instead. ↓
fix Remove 'throw-if-namespace' and set 'react.runtime' to 'automatic'.
gotcha Class properties loose mode may affect compatibility with older mini-program runtimes; test thoroughly. ↓
fix Set 'class-properties.loose' to false if strict spec compliance is needed.
gotcha Enabling 'decorators.legacy' requires 'class-properties.loose' to be true for correct ordering. ↓
fix Set both 'decorators.legacy: true' and 'class-properties.loose: true'.
breaking Babel 7.0+ is required; older versions will fail with 'Cannot find module'. ↓
fix Upgrade @babel/core to >=7.0.0.
Install
npm install babel-preset-remax yarn add babel-preset-remax pnpm add babel-preset-remax Imports
- default
module.exports = require('babel-preset-remax') - remax wrong
presets: ['babel-preset-remax']correctpresets: ['remax'] - Options
interface RemaxPresetOptions { react?: object; typescript?: object; decorators?: object; 'class-properties'?: object; 'throw-if-namespace'?: boolean; }
Quickstart
// babel.config.js
module.exports = {
presets: [
['remax', {
react: { runtime: 'automatic' },
typescript: { allowNamespaces: true },
'class-properties': { loose: true },
'throw-if-namespace': false
}]
]
};