Open vsobotka opened 1 year ago
Not able to recreate this issue but one of my users is reporting the same.
The reason for this error may be the .node file cannot find the .dll file in the same directory.
I used esbuild to bundle dependencies. Initially, the build parameters were as follows:
{
entryPoints: ["./src/main.ts"],
bundle: true,
platform: "node",
outfile: "./dist/main.js",
target: "es2017",
format: "cjs",
external: ["electron", "steamworks.js"],
sourcemap: true,
}
These build parameters externalize steamworks.js, meaning it will not be bundled. Running not result in any errors.
Then, I changed the parameters to:
{
entryPoints: ["./src/main.ts"],
bundle: true,
platform: "node",
outfile: "./dist/main.js",
target: "es2017",
format: "cjs",
external: ["electron"],
sourcemap: true,
loader: {
".node": "copy",
}
}
These parameters bundle steamworks.js and correctly copy the .node files.
However, I encountered an error during runtime:
Error: The specified module could not be found.
I realized that the error was due to the fact that these files were not copied. esbuild cannot bundle these files. The following files need to be manually copied to the dist directory:
node_modules\steamworks.js\dist\linux64\libsteam_api.so
node_modules\steamworks.js\dist\osx\libsteam_api.dylib
node_modules\steamworks.js\dist\win64\steam_api64.dll
node_modules\steamworks.js\dist\win64\steam_api64.lib
In addition, if you manually add dll, you also need to set the packagerConfig.asar
option to false
in forge.config.js
. Otherwise, after executing electron-forge package
, the packaged product will still prompt:
Error: The specified module could not be found.
The content of my forge.config.js
configuration file used for my project(pnpm + electron-forge + esbuild
) is as follows:
module.exports = {
packagerConfig: {
asar: false,
prune: false,
ignore: [/node_modules/],
},
rebuildConfig: {},
makers: [
{
name: "@electron-forge/maker-squirrel",
config: {},
},
{
name: "@electron-forge/maker-zip",
platforms: ["darwin"],
},
{
name: "@electron-forge/maker-deb",
config: {},
},
{
name: "@electron-forge/maker-rpm",
config: {},
},
],
plugins: [],
};
@LZQCN Thank you your solution worked.
Altough i only needed to copy the files steamapi64.dll
and steamapi64.lib
from the win64
to make it work.
That solution only works for windows, in most other cases you should copy the entire dist directory
In my forge.config.js
i use the postPackage
hook to copy these around.
Pre-flight checklist
Electron Forge version
6.0.5
Electron version
23.0.0
Operating system
Windows 11 Home, 22H2
Last known working Electron Forge version
No response
Expected behavior
The app opens.
Actual behavior
I get the following error when trying to run the app either from the exe generated by
make
or when started withstart
command.I verified all the files mentioned above, and they are present on the location they are expected.
Steps to reproduce
Simple electron app with steamworks.js ran on Windows 11 in Parallels Desktop should reproduce the issue. Not sure if it's important, but I use M2 Apple Silicon chip.
Additional information
Until we added steamworks.js, the app was working.
Not sure if it can be related, but I am running the project on M2 MacBook Pro, where I have Parallels Desktop and Windows 11 Home installed. So it is 64bit architecture running on ARM hardware. It is working for a colleague with Windows 11 machine just fine.