[英]cannot use native node module in electron-forge app
I am trying to use pkcs11js in an electron app created with electron-forge using webpack template.我正在尝试在使用webpack模板通过电子锻造创建的 electron 应用程序中使用 pkcs11js。
But I got the error但我得到了错误
Error: C:\ws-p\electron-test\.webpack\main\349a63bd9833f80e7879a5bbfb2a4af2.node is not a valid Win32 application.
←[90m at Object.Module._extensions..node (internal/modules/cjs/loader.js:1122:18)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:928:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:769:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m
←[90m at internal/main/run_main_module.js:17:47←[39m
There are lots of questions asked around but none of the provided solutions/answers worked for me so far.周围有很多问题,但到目前为止,没有一个提供的解决方案/答案对我有用。
None of these worked out:这些都没有解决:
electron-rebuild
(although electron-forge uses this internally)electron-rebuild
(虽然电子锻造在内部使用它)node-gyp rebuild --target=13.1.0 --arch=x64 --dist-url=https://electronjs.org/headers
manually for the packagenode-gyp rebuild --target=13.1.0 --arch=x64 --dist-url=https://electronjs.org/headers
//electronjs.org/headersEnvironment :环境:
Windows 10 Pro
Node 14.16.1
electron: 13.1.0
electron-rebuild: 2.3.5
electron-forge: 6.0.0-beta.57
pkcs11js: 1.2.4
You should use the Electron Forge Webpack template which has better support for native modules.您应该使用 Electron Forge Webpack 模板,它对原生模块有更好的支持。
There is currently anopen issue for this functionality caused by the outdated/unmaintained @marshallofsound/webpack-asset-relocator-loader
which caters for native modules via Webpack.此功能目前存在一个未维护的问题,这是由过时/未维护的
@marshallofsound/webpack-asset-relocator-loader
引起的,它通过 Webpack 满足本机模块的需求。 I'm currently working on a PR to fix this but in the meantime you can use my updated fork .我目前正在做一个PR来解决这个问题,但与此同时你可以使用我更新的 fork 。
None of the solutions on the web worked for me. web 上的解决方案都不适合我。 What worked is defining
electron-gyp
output folder as home before electron-rebuild
or with electron-forge right after/before dependencies install.有效的方法是将
electron-gyp
gyp output 文件夹定义为electron-rebuild
之前的主页或在依赖项安装之后/之前使用电子锻造。
In a terminal:在终端中:
Windows: Windows:
set HOME=C:\Users\YourUser\.electron-gyp
npm i
npm run start <# which resolves to electron-forge start #>
Unix: Unix:
$ export HOME=~/.electron-gyp
$ npm i
$ npm run start # which resolves to electron-forge start
I hope it helps to someone我希望它对某人有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.