miniflare
miniflare copied to clipboard
__STATIC_CONTENT_MANIFEST is empty - can't list files in the Workers Site
When using Workers Site, import manifestJSON from '__STATIC_CONTENT_MANIFEST'
imports a variable manifestJSON
 that contains the JSON manifest, encoded as string, which lists all files in the Site.
Using Miniflare, that manifest is empty.
I understand from the docs that this is by design, however there are situations where accessing the manifest is needed. My app does that to match the correct file to return (e.g. if the extension is missing)
Svelte Kit's adapter cloudflare-workers
is another app (more popular/relevant than what I'm building :) ) that needs that.
Currently, this behavior is preventing me from being able to use Miniflare.
Hey! 👋 Thanks for raising this. As mentioned in the docs you linked, the reason I did this was to disable caching, which would serve outdated files. Wrangler solves this problem by uploading files with a content hash appended to their name. I can think of a couple potential solutions:
- Don't store hashes in the manifest (
{ "index.html": "index.html" }
), but purge site files from the cache on reload - Store hashes in the manifest (
{ "index.html": "index.abcde.html" }
), but remove them when performing file lookups (i.e.__STATIC_CONTENT.get("index.abcde.html")
would actually lookupindex.html
). If we went with this option, we could add a magic string to make removing the hash easier (e.g.index.$MF_HASH:abcde$.html
).
I'm tempted to go with option 1, even though I don't like the idea of deleting cached files especially with the --cache-persist
flag enabled, but am open to suggestions.
Thanks for responding and acknowledging the issue!
I'll be honest that I am not familiar enough with the inner workings of Wrangler. I will trust your judgement on this!
@ItalyPaleAle are you passing sitePath
value when initializing Miniflare?
const mf = new Miniflare({
scriptPath: "index.js",
sitePath: "public",
modules: true,
});
See Cloudflare Starter Kit → site/index.ts
, test/test.ts
@koistya I'm using the CLI and I'm passing the --site
flag.
Oh, I see, it works with Miniflare
server, but not with jest-environment-miniflare
(VM linker).
I had to add a stub for __STATIC_CONTENT_MANIFEST
to make it work with jest-environment-miniflare
:
jest.config.js
export default {
...
moduleNameMapper: {
__STATIC_CONTENT_MANIFEST: "<rootDir>/test/manifest.ts",
},
...
};
test/manifest.ts
/**
* __STATIC_CONTENT_MANIFEST stub
*/
export default "{}";