Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow electron `requires` to passthrough untouched in Vite

When trying to use custom-electron-titlebar , I get an error when it tries to access path . I've added

build: { rollupOptions: { external: ["electron", ...builtinModules],   }}

to my vite config, and that seems to allow me to require('path') in my own code just fine, but when the imported code inside custom-electron-titlebar tries to do the same, it fails to work. It appears to be a wrapped/proxy object, if I call it directly I get an error.

Module "path" has been externalized for browser compatibility and cannot be accessed in client code.

Is there a way to get these requires to passthrough as well?

like image 497
GitNick Avatar asked Oct 28 '25 01:10

GitNick


1 Answers

As mentioned in vitejs/vite#2985, the plugin vite-plugin-commonjs-externals can fix this for us. In vite.config.js:

import commonjsExternals from 'vite-plugin-commonjs-externals';
export default {
  plugins: commonjsExternals({
    externals: ['path'],
  }),
};
like image 124
lights0123 Avatar answered Oct 31 '25 00:10

lights0123



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!