Yarn构建失败:TS5052配置错误与Babel找不到../buildMatchMemberExpression模块问题
Let's break down and fix the two build errors you're encountering when running yarn build for your @mypackage/ui-components package:
1. Resolving the TypeScript TS5052 Error
The error Option 'jsxFragmentFactory' cannot be specified without specifying option 'jsxFactory' points to a misconfiguration in your tsconfig.build.json file. Here's how to fix it:
- For React 17+ automatic JSX transform:
Open yourtsconfig.build.jsonand update thecompilerOptionssection to use React's modern JSX handling:
React 17+ automatically imports JSX utilities, so those two options are no longer required and will cause conflicts if set.{ "compilerOptions": { "jsx": "react-jsx", // Remove any explicit `jsxFragmentFactory` or `jsxFactory` entries } } - If you need the legacy JSX transform:
If you must usejsx: "react"in your config, you must define both options together:{ "compilerOptions": { "jsx": "react", "jsxFactory": "React.createElement", "jsxFragmentFactory": "React.Fragment" } }
2. Fixing the Babel Cannot find module '../buildMatchMemberExpression' Error
This error usually comes from version mismatches between Babel core and your plugins, or an outdated microbundle version (since you're using microbundle to handle the build):
Option A: Upgrade Microbundle
Your current microbundle version (0.15.0) is outdated, which can cause compatibility issues with modern Babel and TypeScript releases. Update it in your package.json:
{ "devDependencies": { "microbundle": "^0.15.1" // Or the latest stable version available on npm } }
Run yarn install to fetch the updated package after making this change.
Option B: Align Babel Plugin Versions
If upgrading microbundle doesn't resolve the issue, verify your Babel plugins are compatible with @babel/core@7.16.0:
- The
babel-plugin-dynamic-import-nodeversion you're using (2.3.3) may be outdated. Try upgrading it to^2.3.4or the latest compatible release. - Ensure all your Babel presets (
@babel/preset-env,@babel/preset-react) match the minor version of@babel/core(7.16.x) to avoid compatibility gaps.
Extra Checks
- Confirm there are no conflicting TypeScript/Babel configurations in parent directories (like a root
tsconfig.jsonor.babelrc) that override your package-specific settings. - After making changes, run
yarn cleanfollowed byyarn buildto eliminate any cached artifacts that might be causing issues.
Quick Cleanup Note
I noticed classnames is listed in both dependencies and devDependencies—you can safely remove the entry in devDependencies to eliminate redundancy.
内容的提问来源于stack exchange,提问作者Ludwig

