Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web APIs polyfill #10

Closed
mustofa-id opened this issue Jun 12, 2023 · 1 comment
Closed

Web APIs polyfill #10

mustofa-id opened this issue Jun 12, 2023 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@mustofa-id
Copy link
Member

mustofa-id commented Jun 12, 2023

Module seperti fetch belum tersedia di Nodejs versi lawas. Kondisikan untuk membuat polyfill untuk memperluas dukungan versi Nodejs. Lihat ini sebagai referensi.

@mustofa-id mustofa-id added the enhancement New feature or request label Jun 12, 2023
@mustofa-id mustofa-id added this to the 1.0.0 milestone Jun 16, 2023
@mustofa-id
Copy link
Member Author

Sepertinya ini tidak perlu sebab:

  • Pada library ini hanya menggunakan fetch tidak banyak module modern lain yang digunakan.
  • Versi NodeJS (v14.x.x LTS) yang belum mendukung fetch sudah EOL.

Untuk NodeJS versi 16.15.0 atau setelahnya sudah mendukung fetch namun dengan flag --experimental-fetch.

node --experimental-fetch app.js

Perlu dicatat bahwa flag --experimental-fetch menunjukan bawah module fetch tersebut masih dalam tahap pengembangan awal atau masih dalam uji coba. Module fetch pada NodeJS sudah stable pada NodeJS versi 18 LTS.

Jika tidak ingin menggunakan flag --experimental-fetch atau versi NodeJS yang digunakan belum mendukung, alternatifnya adalah menginstall package yang terdapat module fetch pihak ketiga seperti node-fetch atau undici. Kami lebih menyarankan menggunakan undici karena dikembangkan langsung oleh NodeJS.

Setelah menginstall package, define fetch sebagai global module seperti ini:

import { fetch } from 'undici';

Object.defineProperty(globalThis, 'fetch', {
    enumerable: true,
    configurable: true,
    writable: true,
    value: fetch
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant