developit / developit/jsdom-worker

Support import and require

Offen
#25 3 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
JavaScript
Sterne
291
Forks
20
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

I'm using jsdom-worker to support third party libs that use service workers in a jest runtime. The third party lib uses require all over the place, which causes issues when jest is otherwise configured as a module (i.e. using import). One way to solve this is to polyfill require -- for example, https://stackoverflow.com/a/71883023/3269537

```js
import { createRequire } from "module";
const require = createRequire(import.meta.url);
```

It would be really convenient if jsdom-worker supported both require and import, so that it is agnostic to what code is actually being loaded. Can we simply inject the above here: https://github.com/developit/jsdom-worker/blob/main/src/index.js#L129? Happy to send out a pr that tries this

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

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