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

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

Open
Angelelz opened this issue Feb 12, 2024 · 4 comments
Open

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

Angelelz opened this issue Feb 12, 2024 · 4 comments

Comments

@Angelelz
Copy link

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
Copy link
Member

Hi @Angelelz

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

The same problem: mugi-tech/honox-blog-template#1

@Angelelz
Copy link
Author

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
Copy link
Author

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

@yusukebe
Copy link
Member

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.

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

2 participants