Preset cloudflare-module error "No such module "__STATIC_CONTENT_MANIFEST"
Environment
node: 18.13.0 nitropack: 2.4.1
Reproduction
https://stackblitz.com/edit/github-y5zrh4?file=package.json
wrangler dev doesn't yet work in stackblitz so you have to download the project and run:
npm inpm run buildnpm run dev
Describe the bug
When building nitro with the preset cloudflare-module and then try to deploy it to cloudflare you get the following error message:
Looking at the output index.mjs file you can see that it imports a file called __STATIC_CONTENT_MANIFEST
But there is not file called __STATIC_CONTENT_MANIFEST in the .output folder
I'm happy to try writing a PR if somebody could lead me into the right direction. What is the static file content manifest and when is it generated?
Additional context
No response
Logs
No response
#1172 is this related?
Thanks to this comment over at the cloudflare/kv-asset-handler repo I was able to get this working by adding the following type declaration file to the root of my Nitro project:
declare module '__STATIC_CONTENT_MANIFEST' {
export default String
}
I named mine manifest.d.ts like in the comment mentioned above, but ideally, I think this should be either produced by Nitro under the .nitro/types dir (at least until Cloudflare can fix this issue) or we should push Cloudflare to resolve this. There are a couple (cloudflare/workers-sdk#4969, cloudflare/workers-sdk#4968) open issues over there already.
After some trial and error I've realized that I didn't properly read the very clear output from Nitro's build command. It says 'wrangler dev .output/server/index.mjs --site .output/public --local', and while the --local part is no longer needed - --site .output/public is. It is the directory that __STATIC_CONTENT_MANIFEST resolves to.
@YannicEl, if you're like me and don't want a whole lot of options passed to your wrangler dev command, just add the following to your wrangler.toml file and you'll be good:
main = './.output/server/index.mjs'
[site]
bucket = './.output/public'
I think you can close this issue as 'not-a-bug'.
For reference, here's a working example with both methods: https://codesandbox.io/p/devbox/nitro-cloudflare-p287wf
cloudflare-module with latest compat date, supports assets on edge. Docs: https://nitro.build/deploy/providers/cloudflare#cloudflare-module-workers