Breaking changes in relation to latest versions of node and the "node-fetch" npm

I guess this post is primarily aimed at extension developers but it helps for everyone to be aware anyway.

For a long time many developers have relied on the "node-fetch" npm to pull data from URLs. which was native to Wappler.

Things have changed and from Node 18, Node introduced a native global fetch() implementation based on the undici npm. (experimental)

From Node 22 the native fetch() was fully optimized, stable, and standard. Because it is baked into the global runtime environment, maintaining node-fetch as a dependency has become redundant for most modern projects. Modern SDKs (like OpenAI's JavaScript SDK) have entirely dropped node-fetch in favour of the native global architecture. (hence TMR reporting All In One AI V2 throwing openai errors recently)

So if environments are guaranteed to be node 22 or after, node 'node-fetch' is depreciated and fetch can be defined:

const fetch = globalThis.fetch;

if you need to be backward compatible then this should work.

let fetch;

if (typeof globalThis !== 'undefined' && globalThis.fetch) {
    // Target: Node 24 (and modern Node 18 environments)
    // Uses the optimized native global fetch engine directly
    fetch = globalThis.fetch;
} else if (typeof global !== 'undefined' && global.fetch) {
    // Target: Standard Node 18/20 environments
    fetch = global.fetch;
} else {
    // Target: Legacy fallback or strictly sandboxed containers
    try {
        // Requires node-fetch dynamically so Node 24 doesn't crash on standard parsing
        fetch = require('node-fetch');
    } catch (e) {
        throw new Error("PayPal Extension Error: Global fetch is unavailable, and 'node-fetch' could not be required.");
    }
}

I will be checking all my extensions to ensure compatibility with the potentially breaking change, should anyone have any issues let me know and i will move that extension to the front of the queue.

4 Likes