-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Not compatible with Electron: Node.js internal modules truncated #2985
Comments
我也有类似的问题 但如果我切换成 import DataStore from 'nedb' |
Share my walkaround here: patch-vite.ts const hack1 = 'req';
const hack2 = 'uire';
const theRequire: any = window[hack1 + hack2 as any];
export default function patchedRequire(module: string): any {
return theRequire(module);
} In your code... import patchedRequire from './patch-vite';
// Vite is incapable of loading node built-in modules.
import type childProcess_t from 'child_process';
import type util_t from 'util';
import type path_t from 'path';
import type fs_t from 'fs';
const childProcess: typeof childProcess_t = patchedRequire('child_process');
const util: typeof util_t = patchedRequire('util');
const path: typeof path_t = patchedRequire('path');
const fs: typeof fs_t = patchedRequire('fs');
... |
So this issue has a better walkaround https://github.com/xiaoxiangmoe/vite-plugin-commonjs-externals thanks to @xiaoxiangmoe. |
@lusase 用上面老哥那个插件就能解,挺好用的。 |
试了一下还是不行... 还是报找不到包 |
这个问题怎么解决的呢? |
vite vue3 element-plus |
同问,怎么解决呢? |
closing as vite is not going support node global builtins and node specific api's on the client |
Shame on you then |
a focus of vite is to promote esm. |
It's not about It's a simple request here:
When the developer says |
@nomagick I suggest you review the way you are directing yourself to Open Source maintainers. As @Niputi said, Electron is out of the scope of Vite at this point, we are focusing on making the best experience possible to build web apps. There are people in the community using Vite for Electron, and we will try to help as possible. But Vite as a project can and will set its own scope and priorities. If you don't agree with them, you are free to use other tools or respectfully engage with us so to work something together. If there is a concrete change that will unblock your use case, I recommend you send a PR so we can see the added complexity. Please state as clearly as possible the use case that this would enable and how you can't achieve the same in userland through plugins. Locking this issue now as I don't think the current line of discussion is productive. |
Describe the bug
Node.js internal modules were turned into empty objects.
Which is valid and needed in Electron enviroments.
And, Node.js only means SSR is a false assumption.
Reproduction
require("utils").promisify()
System Info
Output of
npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:Used package manager: npm
Logs
Before submitting the issue, please make sure you do the following
The text was updated successfully, but these errors were encountered: