honojs / honox

HonoX - Hono based meta framework
https://hono.dev
MIT License
1.28k stars 38 forks source link

How to use packages written in commonjs on the server #43

Open Angelelz opened 6 months ago

Angelelz commented 6 months ago

I'm hitting a wall trying to make my server do the stuff I need it to do with packages that are written in commonjs using require. I'm not super familiar with vite's bundling process so there's little I can investigate here.

The error I'm getting is: [vite] Internal server error: require is not defined

yusukebe commented 6 months ago

Hi @Angelelz

Thanks. I'll try to fix this issue later.

The same problem: https://github.com/mugi-tech/honox-blog-template/issues/1

Angelelz commented 6 months ago

I found a workaround / solution:

ssr: {
  external: ["adm-zip", "mssql", "sanitize-filename"],
},

Add that to the backend packages that use require on the server part of vite.config.ts

Angelelz commented 6 months ago

Feel free to close the issue. It's working fine for me.

yusukebe commented 6 months ago

Hi @Angelelz

This error comes from the lack of CommonJS support by Vite. It is better to write the appropriate package name in ssr.external as you did.