{"id":19344,"library":"babel-preset-taro","title":"babel-preset-taro","description":"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.","status":"active","version":"4.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/NervJS/taro","tags":["javascript"],"install":[{"cmd":"npm install babel-preset-taro","lang":"bash","label":"npm"},{"cmd":"yarn add babel-preset-taro","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-preset-taro","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency for Babel compilation","package":"@babel/core","optional":false},{"reason":"peer dependency for React Fast Refresh","package":"react-refresh","optional":true},{"reason":"peer dependency for React Native support","package":"@tarojs/taro-rn","optional":true},{"reason":"peer dependency for Solid.js support","package":"babel-preset-solid","optional":true},{"reason":"peer dependency for React JSX","package":"@babel/preset-react","optional":true},{"reason":"peer dependency for Vue JSX","package":"@vue/babel-plugin-jsx","optional":true},{"reason":"peer dependency for Preact Refresh","package":"@prefresh/babel-plugin","optional":true}],"imports":[{"note":"This package is not ESM-friendly; use CommonJS require for babel.config.js.","wrong":"import taroPreset from 'babel-preset-taro'","symbol":"default","correct":"module.exports = { presets: [['babel-preset-taro', { framework: 'react' }]] }"},{"note":"withTaro is a helper to extend the preset; requires CommonJS.","wrong":"import { withTaro } from 'babel-preset-taro'","symbol":"withTaro","correct":"const { withTaro } = require('babel-preset-taro')"},{"note":"getPreset returns a presets array; only available via CommonJS require.","wrong":null,"symbol":"getPreset","correct":"const { getPreset } = require('babel-preset-taro')"}],"quickstart":{"code":"// babel.config.js\nmodule.exports = function (api) {\n  api.cache(true);\n  return {\n    presets: [\n      ['babel-preset-taro', {\n        framework: 'react',\n        ts: true,\n        react: {\n          runtime: 'automatic',\n        },\n      }],\n    ],\n    plugins: [\n      ['@babel/plugin-transform-runtime', { corejs: 3 }],\n    ],\n  };\n};","lang":"javascript","description":"Configures Babel for a Taro React project with TypeScript support and automatic JSX runtime."},"warnings":[{"fix":"Upgrade Node.js to version 18 or higher.","message":"Requires Node >= 18, dropping support for Node 14 and 16.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Use framework: 'react' or 'vue' and configure Vite via @tarojs/plugin-vite-devtools.","message":"The 'vite' framework option is deprecated in favor of 'react' or 'vue' with separate Vite plugins.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Install @vue/babel-plugin-jsx@^1.2.2 for Vue 3.","message":"If using with Vue, ensure @vue/babel-plugin-jsx version matches your Vue version (3.x).","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Remove any manual JSX presets and rely on babel-preset-taro's framework selection.","message":"The preset automatically adds plugins for React, Vue, or Solid based on the 'framework' option. Do not manually add conflicting presets like @babel/preset-react.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Install @tarojs/taro-rn@4.2.0 as a devDependency.","message":"For React Native (RN) projects, you must install @tarojs/taro-rn as a peer dependency even if not used in the final app.","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run npm install @babel/core --save-dev","cause":"@babel/core is a peer dependency not installed.","error":"Error: Cannot find module '@babel/core'"},{"fix":"Use framework: 'vue', or if using Vue, install @vue/babel-plugin-jsx","cause":"Misspelled framework name or missing peer dependency.","error":"Error: Framework 'vue' is not supported by babel-preset-taro"},{"fix":"Change babel.config.js to use module.exports = { presets: [...] } instead of export default.","cause":"Using ES module import syntax in babel.config.js which expects CommonJS.","error":"Error: Plugin/Preset files are not allowed to export objects, only functions."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}