Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

安装了electron-updater,打包之后报错:“Cannot find module electron-updater”。 #27

Closed
hemengke1997 opened this issue Apr 16, 2021 · 15 comments

Comments

@hemengke1997
Copy link

如题。本地运行没有问题,打包之后就会报错。
项目只有根目录下的一个package.json文件
image

烦请作者指点,感激不尽

@BySlin
Copy link
Owner

BySlin commented Apr 16, 2021

把electron-updater放在dependencies中

@hemengke1997
Copy link
Author

把electron-updater放在dependencies中

image

您看,确实是在dependecies里。
我刚才检查了打包出来的文件,package.json中只有 electron-devtools-installer

@BySlin
Copy link
Owner

BySlin commented Apr 16, 2021

image
把electron-updater配置到这里来

@BySlin
Copy link
Owner

BySlin commented Apr 16, 2021

将一些不能打包的包配置在electronBuilder下的externals中,只需要写包名,打包后即可使用

@hemengke1997
Copy link
Author

将一些不能打包的包配置在electronBuilder下的externals中,只需要写包名,打包后即可使用

已解决,感谢作者。还想请问一个问题:
我按照 #24 中您的回答,把prefix改为了我司域名,依然无法进行http请求。请问在electron开发中,renderer的请求应该放在主进程中吗? 还是说按照网页开发,把页面请求放在页面中?

@BySlin
Copy link
Owner

BySlin commented Apr 16, 2021

将webSecurity设置为false 即可跨域,页面就可以直接请求了
通过contextIsolation设置为true,不开启nodeIntegration ,和contextBridge.exposeInMainWorld调用node环境下的方法,保证安全

@hemengke1997
Copy link
Author

将webSecurity设置为false 即可跨域,页面就可以直接请求了
通过contextIsolation设置为true,不开启nodeIntegration ,和contextBridge.exposeInMainWorld调用node环境下的方法,保证安全

感谢作者指点。我刚上手electron,目前做法是开启了nodeIntegration,关闭了contextIsolation,个人感觉主进程与渲染进程通过contextBridge通信有点麻烦,对于以后的代码维护也不太好。请问您有比较好的实践项目吗?想学习一下

@hemengke1997
Copy link
Author

将webSecurity设置为false 即可跨域,页面就可以直接请求了
通过contextIsolation设置为true,不开启nodeIntegration ,和contextBridge.exposeInMainWorld调用node环境下的方法,保证安全

页面的http请求应该放在主进程中还是渲染进程中呢?如果放在渲染进程中,按您所说的,可能不安全。如果放在主进程中,每次请求都需要与主进程通信,主进程会因为去做这些请求而卡顿吗

@BySlin
Copy link
Owner

BySlin commented Apr 18, 2021

页面的请求放在渲染进程中即可,对node的调用建议使用contextBridge,不建议使用nodeIntegration,开了nodeIntegration才不安全,网页中能执行node代码,就权限太高了,可能会被乱用,应该通过contextBridge限定网页能调用的方法,只要你不从网络加载代码,一般不会有问题
image

@hemengke1997
Copy link
Author

@BySlin 请问作者,public文件夹中的文件,打包之后没有了,这种情况该如何处理呢?

@BySlin
Copy link
Owner

BySlin commented Apr 20, 2021

image
打包后存在啊
如果要public的文件不打包进app.asar,得按electron-builder的方式配置

@hemengke1997
Copy link
Author

image
打包后存在啊
如果要public的文件不打包进app.asar,得按electron-builder的方式配置

这是打包命令
image
这是打包后的文件目录
image

😓 请问您有什么想法或者思路吗 我顺着您的思路去检查代码

@hemengke1997
Copy link
Author

image
打包后存在啊
如果要public的文件不打包进app.asar,得按electron-builder的方式配置

我用您的demo代码尝试了一下,加了public文件夹,打包结果也没有那些静态文件

@BySlin
Copy link
Owner

BySlin commented Apr 20, 2021

用双目录结构public得放在src/renderer/下 @hemengke1997

@hemengke1997
Copy link
Author

用双目录结构public得放在src/renderer/下 @hemengke1997

谢谢作者,已经解决了。请问这样做的原理是什么呢? 我一直以为public目录位置应该跟APP_ROOT同级,完全没想到要放在APP_ROOT(即rederer)下面

@BySlin BySlin closed this as completed Apr 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants