Support Babel 8 in babelParser (loadPartialConfigSync)

未关闭 适合新手
#1,102 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
react, typescript
领域
tooling

调研方向

从 dist/babelParser.js 中所示的同步 babelParser 路径开始,检查 loadPartialConfig 调用。使用提供的 repro.mjs 和 @babel/core 8.0.1,然后验证在保持与 Babel 7 兼容的同时,使用 Babel 8 解析能够成功。

由索引模型根据 Issue 内容生成。

描述

Description

react-docgen@8.0.3 cannot parse components when its @babel/core dependency is resolved to Babel 8.

babelParser calls loadPartialConfig synchronously. Starting with Babel 8, that API expects a callback; synchronous callers must use loadPartialConfigSync.

This surfaced through Storybook's react-docgen plugin when a workspace-wide override resolved Babel to 8.0.1. Storybook is currently tracking Babel 8 support and explicitly waiting for react-docgen compatibility: https://github.com/storybookjs/storybook/issues/35295

Minimal reproduction

package.json:

{
  "private": true,
  "type": "module",
  "packageManager": "pnpm@11.13.0",
  "dependencies": {
    "@babel/core": "8.0.1",
    "react-docgen": "8.0.3"
  }
}

pnpm-workspace.yaml:

packages:
  - .

overrides:
  '@babel/core': 8.0.1

repro.mjs:

import { parse } from 'react-docgen';

parse('export const Button = ({ label }) => <button>{label}</button>;');

Run:

pnpm install
node repro.mjs

Actual result

Error: Starting from Babel 8.0.0, the 'loadPartialConfig' function expects a callback. If you need to call it synchronously, please use 'loadPartialConfigSync'.
    at loadPartialConfig (.../@babel/core/lib/index-shared.js:2207:11)
    at buildPluginList (.../react-docgen/dist/babelParser.js:34:27)

Expected result

Parsing succeeds with Babel 8, while retaining Babel 7 compatibility.

Versions

  • react-docgen: 8.0.3
  • @babel/core: 8.0.1
  • Node.js: 24.18.0
  • pnpm: 11.13.0

The likely compatibility change is to use loadPartialConfigSync for this synchronous code path; that API is also available in Babel 7.

主要语言
TypeScript
星标
3.8k
派生
316
平均合并
5 小时 7 分钟
30 天内合并 PR
4

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

reactjs/react-docgen 的其他 Issue

查看 reactjs/react-docgen 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。