maugenst / tabletojson

An npm module for node.js to convert HTML tables to JSON objects
https://www.npmjs.com/package/tabletojson
MIT License
138 stars 38 forks source link

[Bug] fetch is not a funcction #83

Closed yyz945947732 closed 1 year ago

yyz945947732 commented 1 year ago
image

I can't run this script in node environment. I think maybe you can add node-fetch package to the project and add polyfill like this:

import fetch from 'node-fetch';

if (!globalThis.fetch) {
  globalThis.fetch = fetch;
}

Then this package should be able to run directly in the node environment.

yyz945947732 commented 1 year ago

Oh, Because my node version is lower than 18.0.0. So fetch api is not support.

image

I just saw that lower versions of node cannot support this library.

maugenst commented 1 year ago

Thanks for your reply.

From node 18 onwards the fetch api is available, but tagged as experimental: https://nodejs.org/en/blog/announcements/v18-release-announce or https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#fetch

Once you upgraded your node to 18+ it should work out of the box.