Open kingyue737 opened 1 month ago
No file named
@serialport/bindings-cpp.native.cjs
is generated
I found the cause. My config was native({})
. But I just found webpack
and forceCopyIfUnbuilt
cannot be omitted here while the documentation says that forceCopyIfUnbuilt
is true
by default.
native({ forceCopyIfUnbuilt: true, webpack: {} })
But now comes another issue, the generated path in bindings-cpp.native.cjs
is very strange:
// This is a native module that cannot be built correctly.
module.exports = require("../D:\Solutions\rho-meter\dist-electron\node_natives\node_modules\@serialport\bindings-cpp");
It seems to be a "relative-absolute" path and the backslash \
in the path will cause error on windows.
Found a workaround without this plugin.
build: [
{
vite: {
plugins: isDev ? [notBundle()] : undefined,
build: {
minify: isProd,
+ commonjsOptions: {
+ ignoreDynamicRequires: true,
+ },
lib: {
entry: 'electron/main.ts',
fileName: 'main',
formats: ['cjs'],
},
},
},
},
]
.node
file to bundle via electron-builder
{
"$schema": "node_modules/app-builder-lib/scheme.json",
"asar": true,
"directories": {
"output": "release/${version}"
},
"files": [
"dist-electron",
".output/**/*",
"!node_modules/**/*"
],
"electronLanguages": ["zh-CN"],
"win": {
"icon": "dist/favicon.ico",
+ "files": [
+ {
+ "from": "node_modules/@serialport/bindings-cpp/prebuilds/win32-x64",
+ "to": "prebuilds/win32-x64"
+ }
+ ],
"target": [
{
"target": "nsis",
"arch": ["x64"]
}
]
},
}
I tried this plugin but the built app throw the following error:
Platform: Windows
Any help is appreciated