Registry / testing / n4js-runtime-fetch

n4js-runtime-fetch

JSON →
library0.29.1jsnpmunverified

N4JS runtime library providing a lightweight polyfill for the whatwg fetch API, designed specifically for N4JS transpiled code. Version 0.29.1 is the latest stable release with no active development or public roadmap. It acts as a bridge for using the fetch API in N4JS projects when targeting Node.js or browsers lacking native fetch. Differentiators: minimal overhead, tight integration with N4JS module system.

npm install n4js-runtime-fetch
INSTALL
IMPORT
SIG · N4JS-RUNTIME-FETCH
N
n4js-runtime-fetch
testingjavascriptv0.29.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fetch
import { fetch } from 'n4js-runtime-fetch'
const fetch = require('n4js-runtime-fetch')
ESM only; the library does not export a default, and CommonJS require will not work.
Request
import { Request } from 'n4js-runtime-fetch'
import Request from 'n4js-runtime-fetch'
Named export, not default; also available from 'whatwg-fetch' but this package re-exports it.
Response
import { Response } from 'n4js-runtime-fetch'
Named export; same as above.

Shows how to use the fetch polyfill for GET requests with async/await and error handling.

import { fetch, Request, Response } from 'n4js-runtime-fetch'; async function getData() { const response = await fetch('https://api.example.com/data', { method: 'GET', headers: { 'Content-Type': 'application/json' } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log(data); } getData().catch(console.error);
Debug
Known issues
gotchaThis package is only intended for use with N4JS transpiled code. Using it in other JavaScript projects may lead to unexpected behavior.
fix
Use 'whatwg-fetch' or 'node-fetch' directly for non-N4JS projects.
affects: *
breakingVersion 0.29.1 switches from a global fetch polyfill to an explicit import-based approach. Existing code relying on global fetch may break.
fix
Update imports to use the package's named exports instead of relying on global fetch.
affects: >=0.29.1
deprecatedThe package is in maintenance mode with no active development. There are no plans for new features or support for newer Node.js versions.
fix
Consider migrating to native fetch (Node.js 18+) or using 'node-fetch' for older versions.
affects: *
gotchaThe fetch implementation does not support all WHATWG fetch features, such as streaming responses or AbortController.
fix
Use a full-featured fetch polyfill like 'node-fetch' if advanced features are required.
affects: *
Errors
Common errors & fixes
TypeError: fetch is not a function
fetch is not imported or the global polyfill is not active. This package requires explicit import.
fix
Use `import { fetch } from 'n4js-runtime-fetch'` instead of requiring blindly.
Cannot find module 'whatwg-fetch'
Missing dependency `whatwg-fetch`. This package depends on it but may not install it automatically in some environments.
fix
Run `npm install whatwg-fetch` as a peer dependency.
Upgrade
Version history
0.29.1latest on npm
Audit
Dependencies
whatwg-fetchrequiredProvides the underlying fetch polyfill for browsers and older Node.js versions.
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
n4js-runtime-fetch — npm install n4js-runtime-fetch · libregistry