-
-
Notifications
You must be signed in to change notification settings - Fork 260
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
Main process code is bundled for browser environment #278
Comments
Because vite was designed for the browser environment, there are some issues with handling specific packages. I'm not sure if there's a way to fix this but You can add |
External not work for this, i can not use a packge without bundle it PS D:\~\src\github.com\cawa-93\vite-electron-builder> npm run watch
> watch
> node scripts/watch.js
下午10:55:31 [main] App threw an error during load
下午10:55:31 [main] TypeError: Koa__namespace is not a constructor
at Object.<anonymous> (D:\~\src\github.com\cawa-93\vite-electron-builder\packages\main\dist\index.cjs:62:1)
at Module._compile (internal/modules/cjs/loader.js:1078:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1108:10)
at Module.load (internal/modules/cjs/loader.js:935:32)
at Module._load (internal/modules/cjs/loader.js:776:14)
at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
at loadApplicationPackage (D:\~\src\github.com\cawa-93\vite-electron-builder\node_modules\electron\dist\resources\default_app.asar\main.js:110:16)
at Object.<anonymous> (D:\~\src\github.com\cawa-93\vite-electron-builder\node_modules\electron\dist\resources\default_app.asar\main.js:222:9)
at Module._compile (internal/modules/cjs/loader.js:1078:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1108:10) Why vite is used to build main/preload code in the first place? |
- import * as Koa from 'koa'
+ import Koa from 'koa' And you need to enable |
It works now, external dependency is handled by electron-builder, seems electron builder not handle transform result of That's a strange workaround because Maybe later i will send a PR to use esbuild directly for main/preload code, because vite is not designed for that. Thanks for the quick response anyway. |
Perhaps you will be better to explore other templates or approaches, since the main idea of this template is using a single build tool for everything. |
Describe the bug
npm run watch
failed withwindow is undefined
after add@koa/router
, caused byany-promise
package.Vite seems only designed to bundle code for browser, so it uses
browser
field ofpackage.json
, and i found no way to disable this behavior.To Reproduce
issue-repro-2021-05-20.zip
Steps to reproduce the behavior:
npm install koa @koa/router @types/koa @types/koa__router
npm run watch
Expected behavior
any-promise
register-shim.js
should not included in bundle because it has been marked for browser only.Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
I searched about bundle for node with vite/rollup, but not found anything useful,
maybe we should use esbuild for main/preload code directly?
The text was updated successfully, but these errors were encountered: