question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

serveStatic not working (ReferenceError: __STATIC_CONTENT_MANIFEST is not defined)

See original GitHub issue

Info

  • hono : 1.3.3
  • wrangler : v2

Wrangler configuration -

name = "test"
main = "src/index.ts"
compatibility_date = "2022-05-13"

kv_namespaces = [
  { binding = "ARNAB", preview_id = "", id="" }
]

[site]
bucket =  "./public"

Code -

import { Hono } from "hono";
import { serveStatic } from "hono/serve-static";
import { renderSSR } from "nano-jsx";
import Home from "./pages/Home";

const app = new Hono();

app.use("/img/*", serveStatic({ root: "./" }));
app.get("/", async (ctx) => ctx.html(renderSSR(Home)));

export default app;

Assets :

./public
└── img
    ├── cf.png

Error :

GET /img/cf.png crashes with an internal server error.

8:46:17 AM GET /img/cf.png 500
ReferenceError: __STATIC_CONTENT_MANIFEST is not defined             
[1]     at getContentFromKVAsset (index.js:718:9)
[1]     at index.js:869:70
[1]     at dispatch (index.js:301:34)
[1]     at index.js:286:16
[1]     at Hono2.dispatch (index.js:660:27)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
yusukebecommented, May 19, 2022

Hi @ArnabXD

I’ve released v1.3.4. The server-static middleware is now supporting Module Worker. You can write like this:

import { Hono } from 'hono'
import { serveStatic } from 'hono/serve-static.module' // <--- New!

const app = new Hono()

app.use('/static/*', serveStatic({ root: './' }))
app.get('/', (c) => c.text('This is Home! You can access: /static/hello.txt'))

export default app
1reaction
yusukebecommented, May 18, 2022

Hi @ArnabXD !

This error occurs only in ES Modules mode.

app.fire // <--- Service Worker mode / do not throw the error

export default app // <--- ES module mode / throw the error

I’m investigating how to fix it. If you want to use serveStatic right now, use Service Worker mode instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ServeStatic not defined - pure node.js - Stack Overflow
This is the code I can't get to work. My error when trying to run: ReferenceError: serveStatic is not defined ...
Read more >
expressjs/serve-static: Serve static files - GitHub
Create a new middleware function to serve files from within a given root directory. The file to serve will be determined by combining...
Read more >
Serving static files in Express
To serve static files such as images, CSS files, and JavaScript files, use the express.static built-in middleware function in Express.
Read more >
How To Serve Static Files in Express - DigitalOcean
In this article, you will learn how to serve static files in Express. ... An understanding of Node.js is suggested but not required....
Read more >
How to Serve Static Files using Express: A Step-by-step Guide
To be able to serve static files with defined routes, we can specify paths in our Express application. ... As you can notice,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found