-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Whitelist for 'Module "..." has been externalized for...' warning #19289
Comments
Hello @sevenc-nanashi. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
This is not a bug, but a feature request. |
The reproduction of the warning would help a lot to understand the current situation and discuss the solution 🙏 |
https://github.com/sevenc-nanashi/vite-feature-request-mute-node-warning I made an example. Let's say:
|
I think the underlying issue is expected to be dealt with in a different way than suppressing the warning. I would imagine that ideally electron renderer build should tree shake out main process specific logic entirely and this can by normally achieved by build-time // vite.config.ts
export default defineConfig({
plugins: [
electron({
main: {
// Shortcut of `build.lib.entry`
entry: "electron/main.ts",
vite: {
define: {
'__ELECTRON_IS_NODE__': 'true'
}
}
},
}),
],
define: {
'__ELECTRON_IS_NODE__': 'false'
},
});
// src/log.ts
export function log(message: string) {
if (__ELECTRON_IS_NODE__) {
if (!electronLog) {
electronLog = import("electron-log/main");
}
electronLog.then(({ default: log }) => {
log.log(message);
});
return;
}
console.log(message);
} I'm closing this feature request since the suggested solution is not likely what Vite core needs to provide. I think this kind of needs can be solved at framework levels by providing a way/convention to branch out the code based on the environment. |
Description
I have an electron app that has
helpers/logger.ts
, a logger which is usable and imported from both electron and browser.The file is like this:
In this module,
electron-log
, a Node.js only package, is imported dynamically, and I knowelectron-log
and its dependent Node.js modules are not used on browser.But vite still warns about that Node.js modules are externalized.
Suggested solution
It would be great if there is option (or possible directive) to mute that warning.
Alternative
Or mute all externalization warning (But this is scary)
Additional context
N/A
Validations
The text was updated successfully, but these errors were encountered: