Skip to content

replace node-fetch with native fetch module (coming with node v18) #2649

@khassel

Description

@khassel

We are using node-fetch for fetching url's in 3 places:

  • calendar
  • newsfeed
  • e2e tests

With the new version v3 they decided to convert node-fetch to ES module so we can not use require anymore. I testet the alternative syntax using const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args)); instead.

The modules calendar and newsfeed are working with this change, but jest is failing with a Segmentation fault:

PID 2750 received SIGSEGV for address: 0x10
/opt/magic_mirror/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x3206)[0x7f18049f3206]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x12730)[0x7f18046b9730]
node[0xa15ec0]
node(_ZN2v88internal7Isolate38RunHostImportModuleDynamicallyCallbackENS0_6HandleINS0_6ScriptEEENS2_INS0_6ObjectEEENS0_11MaybeHandleIS5_EE+0xad)[0xe4bb5d]
node(_ZN2v88internal25Runtime_DynamicImportCallEiPmPNS0_7IsolateE+0xb1)[0x11fd7d1]
node[0x15ce134]

AFAIS this error comes from the headless chromium browser used for the e2e tests.

At this point I stopped my PR for using node-fetch v3. They still support v2 with security patches, so we have no problem yet.

For the future we need a solution for this or have to use antoher library.

In package.json node-fetch must stay on v2.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions