nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Preset cloudflare-module error "No such module "__STATIC_CONTENT_MANIFEST"

Open YannicEl opened this issue 2 years ago • 3 comments

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:

  1. npm i
  2. npm run build
  3. npm 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: image

Looking at the output index.mjs file you can see that it imports a file called __STATIC_CONTENT_MANIFEST image

But there is not file called __STATIC_CONTENT_MANIFEST in the .output folder image

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

YannicEl avatar Jun 18 '23 14:06 YannicEl

#1172 is this related?

YannicEl avatar Jun 18 '23 14:06 YannicEl

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.

ChristianJacobsen avatar Jan 09 '24 07:01 ChristianJacobsen

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

ChristianJacobsen avatar Jan 24 '24 21:01 ChristianJacobsen

cloudflare-module with latest compat date, supports assets on edge. Docs: https://nitro.build/deploy/providers/cloudflare#cloudflare-module-workers

pi0 avatar Jan 07 '25 17:01 pi0