Registry / web-framework / babel-preset-taro

babel-preset-taro

JSON →
library4.2.0jsnpmunverified

Babel preset for Taro projects, enabling JSX compilation for React, Vue, Solid, and Prefresh frameworks. Current stable version is 4.2.0, released on 2025-04-01. Release cadence: irregular, with frequent patch releases. Key differentiator: supports cross-platform app development (WeChat, Alipay, Baidu, HarmonyOS, H5, RN) by automatically configuring Babel plugins based on the target framework. Requires Node >= 18. Part of the NervJS/Taro monorepo. Alternatives: manual Babel config with individual presets.

npm install babel-preset-taro
INSTALL
IMPORT
SIG · BABEL-PRESET-TARO
B
babel-preset-taro
web-frameworkjavascriptv4.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
module.exports = { presets: [['babel-preset-taro', { framework: 'react' }]] }
import taroPreset from 'babel-preset-taro'
This package is not ESM-friendly; use CommonJS require for babel.config.js.
withTaro
const { withTaro } = require('babel-preset-taro')
import { withTaro } from 'babel-preset-taro'
withTaro is a helper to extend the preset; requires CommonJS.
getPreset
const { getPreset } = require('babel-preset-taro')
getPreset returns a presets array; only available via CommonJS require.

Configures Babel for a Taro React project with TypeScript support and automatic JSX runtime.

// babel.config.js module.exports = function (api) { api.cache(true); return { presets: [ ['babel-preset-taro', { framework: 'react', ts: true, react: { runtime: 'automatic', }, }], ], plugins: [ ['@babel/plugin-transform-runtime', { corejs: 3 }], ], }; };
Debug
Known issues
breakingRequires Node >= 18, dropping support for Node 14 and 16.
fix
Upgrade Node.js to version 18 or higher.
affects: >=4.0.0
deprecatedThe 'vite' framework option is deprecated in favor of 'react' or 'vue' with separate Vite plugins.
fix
Use framework: 'react' or 'vue' and configure Vite via @tarojs/plugin-vite-devtools.
affects: >=4.0.0
gotchaIf using with Vue, ensure @vue/babel-plugin-jsx version matches your Vue version (3.x).
fix
Install @vue/babel-plugin-jsx@^1.2.2 for Vue 3.
affects: >=4.0.0
gotchaThe preset automatically adds plugins for React, Vue, or Solid based on the 'framework' option. Do not manually add conflicting presets like @babel/preset-react.
fix
Remove any manual JSX presets and rely on babel-preset-taro's framework selection.
affects: >=4.0.0
gotchaFor React Native (RN) projects, you must install @tarojs/taro-rn as a peer dependency even if not used in the final app.
fix
Install @tarojs/taro-rn@4.2.0 as a devDependency.
affects: >=4.0.0
Errors
Common errors & fixes
Error: Cannot find module '@babel/core'
@babel/core is a peer dependency not installed.
fix
Run npm install @babel/core --save-dev
Error: Framework 'vue' is not supported by babel-preset-taro
Misspelled framework name or missing peer dependency.
fix
Use framework: 'vue', or if using Vue, install @vue/babel-plugin-jsx
Error: Plugin/Preset files are not allowed to export objects, only functions.
Using ES module import syntax in babel.config.js which expects CommonJS.
fix
Change babel.config.js to use module.exports = { presets: [...] } instead of export default.
Upgrade
Version history
4.2.0latest on npm
Audit
Dependencies
@babel/corerequiredpeer dependency for Babel compilation
react-refreshoptionalpeer dependency for React Fast Refresh
@tarojs/taro-rnoptionalpeer dependency for React Native support
babel-preset-solidoptionalpeer dependency for Solid.js support
@babel/preset-reactoptionalpeer dependency for React JSX
@vue/babel-plugin-jsxoptionalpeer dependency for Vue JSX
@prefresh/babel-pluginoptionalpeer dependency for Preact Refresh
Agent activity
10 hits · last 30 days
node
8
Amazon
1
OpenAI (training)
1
Resources
babel-preset-taro — npm install babel-preset-taro · libregistry