WebPack不包括电子锻造和SerialPort的模块
我正在使用电子福用Webpack模板。 遇到了一些问题,但有序列上的工作。
但是现在,当我运行以导出该应用程序时,如果我不将Node_modules文件夹复制到导出的WebPack文件夹,则在运行应用程序时,将显示serialport显示出错误。
我知道我必须在配置文件中做错了什么,但是什么?我觉得那是缺少的。
我正在使用const {serialport} = est(“ require('requiel('serialport')”);
使用const {serialport} = require('SerialPort');
i获取错误'未找到平台= Win32 Arch = x64 runtime = electron abi = 103 uv = 1 libc = glibc node = 16.13.2 electron = 18.0.0 webpack = true'true'
I'm using the electron-forge webpack template.
Had some issues but got serialport working.
But now when I run make to export the app, if I don't copy the node_modules folder to the exported webpack folder, when I run the app it shows serialport not found error.
I know that I must be doing something wrong in the config file, but what? I feel that's something missing.
I'm using const { SerialPort } = eval("require('serialport')");
When using const { SerialPort } = require('serialport');
I get the error 'No native build was found for platform=win32 arch=x64 runtime=electron abi=103 uv=1 libc=glibc node=16.13.2 electron=18.0.4 webpack=true'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是
electron-forge
您需要了解两件事。为了使用
serialport
之类的本机模块,您必须将模块作为外部模块包含在WebPack配置中。如果将模块列为外部,则将在包装过程中修剪。因此,在锻造配置中,您需要在建筑过程中包括钩子。
If you are using
electron-forge
there are 2 things you need to understand.In order to use native modules like
serialport
, you have to include the modules as an external module in webpack config.If a module is listed as external, it will be pruned during the packaging process. So in your forge config, you need to include hooks during your building process.
谢谢您的答案。它对我有很大帮助。找到有关钩子的更多信息,请找到在这里。
我需要对代码进行一些修改。
在
中,readpackagejson
挂钩将所有脚本删除为post -install
and准备
在./ OUT
中安装依赖项时会导致错误:和
packagewterprune
钩子:Thank you for this answer. It helped me a lot. More information regarding hooks is found here.
I needed to modify the code a bit.
In
readPackageJson
hook removed all the scripts aspostInstall
andprepare
caused errors while installing dependencies in the./out
:And in
packageAfterPrune
hook: