Skip to content

Internal server error: Can't find variable: require #199

@bene

Description

@bene

What version of HonoX are you using?

0.1.23

What steps can reproduce the bug?

I want do create an upload route which uses the @aws-sdk/client-s3 package. However when I use it as I do normally the error below gets thrown. I tried the minio package which also didn't work. I guess it's a common issue with packages?

  1. Start new HonoX project: bun create hono@latest
  2. Install S3 client: bun add @aws-sdk/client-s3
  3. Create
// app/routes/api/upload.ts
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
import { Hono } from "hono";

const app = new Hono();

const s3 = new S3Client({
  region: process.env.S3_REGION as string,
  forcePathStyle: true,
  endpoint: process.env.S3_URL as string,
  credentials: {
    accessKeyId: process.env.S3_ACCESS_KEY_ID as string,
    secretAccessKey: process.env.S3_ACCESS_KEY_SECRET as string,
  },
});

app.post("/", (c) => {
  // Use s3 client
});

export default app;

What is the expected behavior?

Be able to use S3 client without issues.

What do you see instead?

1:43:51 PM [vite] Error when evaluating SSR module /Users/bene/Code/share/app/server.ts:
|- ReferenceError: Can't find variable: require
    at <anonymous> (:5:26)
    at anonymous (:1:26)
    at <anonymous> (/Users/bene/Code/share/node_modules/vite/dist/node/chunks/dep-C1-ZB6nQ.js:53450:5)
    at processTicksAndRejections (:12:39)

1:43:51 PM [vite] Internal server error: Can't find variable: require
      at <anonymous> (:5:26)
      at anonymous (:1:26)
      at <anonymous> (/Users/bene/Code/share/node_modules/vite/dist/node/chunks/dep-C1-ZB6nQ.js:53450:5)
      at processTicksAndRejections (:12:39)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions