`new URL('./source.js', import.meta.url)` produces a URL ending in `[object%20Module]` with a `javascript/auto` rule

Aperta
#23,271 8 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #23312 di @thisisvaishnav — chiusa senza merge

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript
Ambito
build-system

Direzione di ricerca

Start with the reproduction repository and run pnpm run webpack and pnpm run webpack:baseline, then compare dist/webpack/with-rule/ against dist/webpack/baseline/. The bug is that with a javascript/auto rule for .js, new URL('./source.js', import.meta.url) resolves to [object Module] and webpack does not emit source.js. Done means the with-rule bundle emits source.js and prints the same URL as the baseline.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area: parser area: runtime
Have you used AI?

Yes

Which part of webpack is affected?

not sure, config (options, defaults, validation)

Bug Description

new URL('./source.js', import.meta.url) to get a link to the original JavaScript file. When a rule sets type: 'javascript/auto' for all .js files, webpack compiles successfully, skips emitting the source file, and generates a URL ending in [object%20Module].

Link to Minimal Reproduction and steps to reproduce

The reproduction repository includes the emitted files. Clone it and run pnpm install --frozen-lockfile, then pnpm run webpack and pnpm run webpack:baseline.

Expected Behavior

The URL should point to the emitted copy of source.js, as it does in the baseline.

Actual Behavior

With the rule, webpack emits only dist/webpack/with-rule/bundle.cjs. Running it prints file:///…/dist/webpack/with-rule/[object%20Module].

Without the rule, webpack also emits dist/webpack/baseline/source.js. The bundle prints file:///…/dist/webpack/baseline/source.js, and cmp confirms that the emitted file matches the original byte for byte.

Environment
System:
  OS: macOS 27.2
  CPU: (18) arm64 Apple M5 Pro
  Memory: 48.00 GB
Binaries:
  Node: 24.15.0
  Yarn: 1.22.22
  npm: 11.12.1
  pnpm: 10.34.4
Packages:
  webpack: 5.112.2
  webpack-cli: 7.3.1
Is this a regression?

None

Last Working Version

No response

Additional Context

No response

Lingua principale
JavaScript
Stelle
66k
Fork
9.7k
Merge medio
8h 12m
PR unite (30g)
541

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di webpack/webpack

Tutte le issue di webpack/webpack

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.