FormidableLabs / FormidableLabs/babel-plugin-transform-define

wrong babel cache using filepath as entry point

Offen
#47 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
unverified
Vorherrschende Sprache
JavaScript
Sterne
242
Forks
29
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Hey folks, thanks for creating this library, I found it very useful.

I'm opening this issue because I found an edge case related to how babel-loader cache works.

babel-loader uses a prop called `cachedIdentifier`. This property determinate if it is necessary or not re-run babel-loader process.

https://github.com/babel/babel-loader/blob/b29516266912fbc50120155fee00efb1b0a19f59/src/index.js#L61

The point here is that it reads the content of the `.babelrc`. All is okay.

The edge case is related with this:

```
{
"plugins": [
["transform-define", "./path/to/config/file.js"]
]
}
```

If you use `babel-plugin-transform-define` specifying a file path, and then you modify the content of the file, in the next babel-loader it will be determinate that a new run is not necessary, so it will be served the last result from the cache that it's different from your expected result!

Literally, I was thinking I was crazy until discovering this.

The fix could be easiest as determinate the new way to calculate `cachedIdentifier`. The problem is, because in my case I'm under Next.js, that's is not something easy to do because Next.js internal doesn't contemplate this modification.

Ideally, we should do that transparently adding a bit of code inside `babel-plugin-transform-define` to detect the edge case, but not sure if we can do that, need to investigate around babel-loader API inside a plugin.

My current workaround is remove the cache before init the process:

```
rm -rf node_modules/.cache/babel-loader && npm run dev
```
but obviously, this is a very bad solution and slow.

any idea? 🙂

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit der verknüpften cachedIdentifier-Logik in babel-loaders src/index.js und überprüfe, wie babel-plugin-transform-define den Pfad zu seiner Konfigurationsdatei erhält oder auflöst. Reproduziere den Fall eines veralteten Caches, indem du die referenzierte Datei änderst, und definiere den Abschluss als Cache-Invalidierung, wenn sich der Inhalt dieser Datei ändert, ohne node_modules/.cache/babel-loader manuell zu entfernen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript
Bereich
build-system
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

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