Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Exported PropTypes shapes get lost in translation

Offen
#766 5 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
javascript, react
Bereich
build-system

Rechercherichtung

Reproduziere den gemeldeten microbundle-Befehl mit dem gemeinsamen LocaleShape-Import und untersuche das generierte Bundle, in dem die exportierte PropTypes-Shape zu null wird. Vergleiche es mit dem funktionierenden Build, der die Shape dupliziert; fertig ist es, wenn importierte Shapes gültig bleiben und die React-Prop-Type-Warnung nicht mehr expected one of [null,null] meldet.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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

Vorherrschende Sprache
JavaScript
Sterne
8.1k
Forks
358
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus developit/microbundle

Alle Issues in developit/microbundle

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.