Closed tcaer closed 4 years ago
This package is an ES module, not CJS. You have to import it like this:
import { CookieJar, fetch } from 'node-fetch-cookies';
If you can't use ES modules for some reason or if you don't want to use them, you can also load it using the esm package:
const esmImport = require('esm')(module);
const { CookieJar, fetch } = esmImport('node-fetch-cookies');
To me this made the trick: https://github.com/lukeed/webpack-modules
The module is imported correctly by using this importer
?
Why did you choose esm modules? It's not even in LTS node, now I need to download more packages just to run this one
I've chosen ESM because of the cleaner import/export syntax. ESM modules are in node LTS behind the --experimental-modules
feature flag and this library is tested on node LTS. In three months node v16 will be LTS, which includes ESM support without a feature flag.
Sure, I started using ESM really early, but at this point every users is free in their choice between ESM or CJS. If it's possible to add CJS support without copying the whole project and adjusting the imports/exports (I haven't looked into that yet), feel free to open a PR. If not and you choose to use CJS you'll have to live with using esmImport
.
I am trying to import the module like so:
const { CookieJar, fetch } = require('node-fetch-cookies');
but I am getting this error message: