Internal server error: Can't find variable: require
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?
- Start new HonoX project:
bun create hono@latest - Install S3 client:
bun add @aws-sdk/client-s3 - 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
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.
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 https://github.com/vitejs/vite/issues/3409
The same issue happened when I tried to use the mysql2 driver.