Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(getting-started): static files on CF Workers #247

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stukennedy
Copy link

there is a requirement to add a manifest to the serveStatic adapter method, the docs correctly shows that you need to import a manifest from the special __STATIC_CONTENT_MANIFEST module

However, this results in a Typescript error, as this module is generated by wrangler. This change to the docs explains how the user can add a type definition so that the error goes away, otherwise they may assume that the example is incorrect.

there is a requirement to add a manifest to the serveStatic adapter method, the docs correctly shows that you need to import a manifest from the special __STATIC_CONTENT_MANIFEST module

However, this results in a Typescript error, as this module is generated by wrangler.
This change to the docs explains how the user can add a type definition so that the error goes away, otherwise they may assume that the example is incorrect.
@@ -183,6 +183,15 @@ app.get('/static/*', serveStatic({ root: './', manifest }))
app.get('/favicon.ico', serveStatic({ path: './favicon.ico' }))
```

TypeScript cannot resolve the special __STATIC_CONTENT_MANIFEST variable used to import the manifest. This variable is specific to Cloudflare Workers' environment and isn't recognized by TypeScript out of the box.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can write "__STATIC_CONTENT_MANIFEST" as a code span:

`__STATIC_CONTENT_MANIFEST`

@@ -183,6 +183,15 @@ app.get('/static/*', serveStatic({ root: './', manifest }))
app.get('/favicon.ico', serveStatic({ path: './favicon.ico' }))
```

TypeScript cannot resolve the special __STATIC_CONTENT_MANIFEST variable used to import the manifest. This variable is specific to Cloudflare Workers' environment and isn't recognized by TypeScript out of the box.
You can tell TypeScript about this special module by declaring it in a type definition file. Create a new .d.ts file in your project, such as custom.d.ts, and add the following declaration:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use a code span for ".d.ts" too:

`.d.ts`

@yusukebe
Copy link
Member

Hi @stukennedy

Thanks! That's a good suggestion. I've left the comments. Please check them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants