eleventy-fetch icon indicating copy to clipboard operation
eleventy-fetch copied to clipboard

Cloudflare Workers: Could not resolve "fs"

Open regisphilibert opened this issue 10 months ago • 0 comments

I've been happily using eleventy-fetch for months in an Astro + Sanity + Netlify environment. Recently trying to move to Cloudflare but when I try to build the site I get this error:

 Could not resolve "fs"
  File:
    node_modules/@11ty/eleventy-fetch/src/AssetCache.js:1:19
  Code:
    > 1 | const fs = require("fs");
        |                   ^
      2 | const fsp = fs.promises; // Node 10+
      3 | const path = require("path");
      4 | const flatCache = require("flat-cache");
  Stacktrace:
Error: Build failed with 29 errors:
node_modules/@11ty/eleventy-fetch/src/AssetCache.js:1:19: ERROR: Could not resolve "fs"
node_modules/@11ty/eleventy-fetch/src/AssetCache.js:3:21: ERROR: Could not resolve "path"
node_modules/@11ty/eleventy-fetch/src/AssetCache.js:5:31: ERROR: Could not resolve "crypto"
node_modules/@11ty/eleventy-fetch/src/RemoteAssetCache.js:1:19: ERROR: Could not resolve "fs"
node_modules/flat-cache/src/cache.js:1:19: ERROR: Could not resolve "path"

I must note that the problem occurs only when using an SSR route (and the cloudflare adapter), when statically building routes, elventy fetch works normally of course.

If I do not import eleventy-fetch, there's no error... I understand this is probably an upstream problem (@astrojs/cloudflare) etc... but if this is something easily fixable from my package.json file, I'd rather ask here first :)

Thanks a ton for the maintainer's hard work on this precious module!

regisphilibert avatar Oct 11 '23 20:10 regisphilibert