Perhaps I should have filed an issue over at https://github.com/mrbbot/node-fetch, but -since it's meant to be used specifically with miniflare- this looked like a better option.
It turns out @mrbbot/node-fetch declares its entrypoints (module, and main) as well as it's type declarations, pointing to files contained in the lib
folder. These files are explicitly included in the npm package though the files
entry of package.json
"main": "lib/index",
"types": "index.d.ts",
"module": "lib/index.mjs",
"files": [
"lib/index.js",
"lib/index.mjs",
"lib/index.es.js",
"index.d.ts"
]
However, said folder is ignored on the package's .gitignore file
# Babel-compiled files
lib
Which would work fine if the package was installed from a package registry, in which the contents of lib
would positively show up. But, in Miniflare, you're requiring node-fetch from github
https://github.com/mrbbot/miniflare/blob/b17d90961e146cf674c0c5c1a4be5e1c998f60a3/package.json#L30
The final result is you get every file that the package would have stripped off, and miss the only one that matters, which is (lib) and miniflare crashes.
Error: Cannot find module '/home/ffflabs/cf-app/node_modules/@mrbbot/node-fetch/lib/index'. Please verify that the package.json has a valid "main" entry
I guess you haven't noticed because your local copy has the built main and module files already. .For the time being I forked miniflare, and installed a modified node-fetch that ensures existense of the entry points.
I have no problem showing that solution, it's just unellegant. You' ll have to consider if it's worth publishing it as an independent module, or, if it's meant for Miniflare only it makes more sente to move it to the main repo.