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

TypeError: Cannot read properties of undefined (reading 'format') #36

Open
zavbala opened this issue Jun 18, 2024 · 2 comments
Open

TypeError: Cannot read properties of undefined (reading 'format') #36

zavbala opened this issue Jun 18, 2024 · 2 comments

Comments

@zavbala
Copy link

zavbala commented Jun 18, 2024

  • Hono version: 4.4.6
  • Hono Og: 0.0.27

Trying to return an image response:

import { Hono } from 'hono';
import { ImageResponse } from 'hono-og';

const app = new Hono();

app.get(':id', () => {
  return new ImageResponse(
    (
      <div
        style={{
          backgroundColor: 'black',
          backgroundSize: '150px 150px',
          height: '100%',
          width: '100%',
          display: 'flex',
          textAlign: 'center',
          alignItems: 'center',
          justifyContent: 'center',
          flexDirection: 'column',
          flexWrap: 'nowrap',
        }}
      >
        <div
          style={{
            fontSize: 60,
            fontStyle: 'normal',
            letterSpacing: '-0.025em',
            color: 'white',
            marginTop: 30,
            padding: '0 120px',
            lineHeight: 1.4,
            whiteSpace: 'pre-wrap',
          }}
        >
          hello hono
        </div>
      </div>
    ),
  );
});

export default app;

and hono throws "TypeError: Cannot read properties of undefined (reading 'format')"

Edit: Using Cloudflare workers

@ColeTownsend
Copy link

@zavbala

Try this

import { Hono } from 'hono';
import { ImageResponse } from 'hono-og';

const app = new Hono();

app.get(':id', (c) => {
const id = c.req.param("id");
  return new ImageResponse(
    (
      <div
        style={{
          backgroundColor: 'black',
          backgroundSize: '150px 150px',
          height: '100%',
          width: '100%',
          display: 'flex',
          textAlign: 'center',
          alignItems: 'center',
          justifyContent: 'center',
          flexDirection: 'column',
          flexWrap: 'nowrap',
        }}
      >
        <div
          style={{
            fontSize: 60,
            fontStyle: 'normal',
            letterSpacing: '-0.025em',
            color: 'white',
            marginTop: 30,
            padding: '0 120px',
            lineHeight: 1.4,
            whiteSpace: 'pre-wrap',
          }}
        >
          hello hono {id}
        </div>
      </div>
    ),
  );
});

export default app;

@Q6Crypto
Copy link

I have the same issue

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

No branches or pull requests

3 participants