Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Exported PropTypes shapes get lost in translation

未关闭
#766 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
javascript, react
领域
build-system

调研方向

使用共享的 LocaleShape 导入重现报告中的 microbundle 命令,并检查生成的 bundle,其中导出的 PropTypes shape 变为 null。将其与复制该 shape 的正常 build 进行比较;当导入的 shape 保持有效且 React prop-type 警告不再报告 expected one of [null,null] 时,即表示完成。

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

描述

question :grey_question:

Hi there,
Thank you for the great work you've done with microbundle. For the record, here is how I'm using the lib:
microbundle --jsx React.createElement --no-compress --format modern,cjs

I'm using react in version 17 and microbundle in version 0.12.0-next.9

I've got a PropType shape that is used in several definitions:

import PropTypes from "prop-types";

 const LocaleShape = PropTypes.shape({
    // two-char language code ("en", "fr", "de")
    tag: PropTypes.string.isRequired,
    // human readable language description
    language: PropTypes.oneOf([PropTypes.object, PropTypes.string]).isRequired,
    //latin, cyrillic, etc.
    script: PropTypes.string,
    // two-char region code ("US", "CA", "GB", "CH")
    region: PropTypes.string,
    // text direction / orientation: right to left, left to right
    orientation: PropTypes.oneOf(["rtl", "ltr"]),
    // optional emoji string for displaying a flag 🇨🇬 🇲🇼 🇹🇩
    flag: PropTypes.string,
    // String that can be used to search for a locale
    keywords: PropTypes.string,
    // locale identifier of the fallback locale
    fallback: PropTypes.string,
    // optional identifier. If not specified, locale identifier will result in the concatenation
    // of tag and region, with a dash separator: "en-GB", "fr-CA", "nl-BE"
    id: PropTypes.string,
});
export default LocaleShape;

This shape is imported in different files:

LocaleChooser.propTypes = {
  value: PropTypes.oneOfType([LocaleShape, PropTypes.arrayOf(LocaleShape)]),
  locales: PropTypes.arrayOf(LocaleShape),
}

When the bundle is built, it looks like the exported PropType shape is turned into null, as explain the warnings I receive in console:

Warning: Failed prop type: Invalid prop `locales[0].language` of value `[object Object]` supplied to `LocaleChooser`, expected one of [null,null].

This warning is suppressed once I remove the imports and duplicate the LocaleShape in every file that requires it. Am I missing a parameter in the command?

Thanks for your help

主要语言
JavaScript
星标
8.1k
派生
358
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

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

developit/microbundle 的其他 Issue

查看 developit/microbundle 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

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