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

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

Open
bene opened this issue Jul 2, 2024 · 3 comments
Open

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

bene opened this issue Jul 2, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@bene
Copy link

bene commented Jul 2, 2024

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

@bene bene added the bug Something isn't working label Jul 2, 2024
@yusukebe
Copy link
Member

yusukebe commented Jul 5, 2024

Hi @bene

I think It's a Vite issue. I've investigated for a while, but I could not find a good solution. It may not support that library.

@EdamAme-x
Copy link

EdamAme-x commented Jul 5, 2024

I ran into the same problem myself, but I put
import require from "node:require" on the code which throw error (but not good idea)

or vitejs/vite#3409

@cometkim
Copy link

The same issue happened when I tried to use the mysql2 driver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants