vite: how to handle "require" statement in third-party module?

Viewed 882

I use an UI library which has "require" statement.

I can use vite to run development mode successfully.

but when I build and preview the dist, the browser fail: Uncaught ReferenceError: require is not defined, because there are some "require" statement in the vendor chunk.

I have tried @rollup/plugin-node-resolve, @originjs/vite-plugin-commonjs but it doesn't work.

How can I fix that ?

1 Answers

many library provide 'run esmodule' method. or try replace require() to import

Related