简体   繁体   English

无法在电子锻造应用程序中使用本机节点模块

[英]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:这些都没有解决:

  • remove & reinstall node_modules删除并重新安装 node_modules
  • use electron-rebuild (although electron-forge uses this internally)使用electron-rebuild (虽然电子锻造在内部使用它)
  • use node-gyp rebuild --target=13.1.0 --arch=x64 --dist-url=https://electronjs.org/headers manually for the package为 package 手动使用node-gyp rebuild --target=13.1.0 --arch=x64 --dist-url=https://electronjs.org/headers //electronjs.org/headers
  • Npm steps defined in electron docs electron 文档中定义的Npm步骤

Environment :环境

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.

相关问题 使用VSCode调试电子锻造应用程序 - Debug electron-forge app with VSCode 使用电子锻造应用程序中的快递服务 static 文件 - Serve static files with express from within electron-forge app 使用带有电子编译和电子松鼠启动的电子锻造初始化电子应用程序时出错 - Error when initialising electron App using electron-forge with electron-compile and electron-squirrel-startup 在电子锻造 + webpack 应用程序中使用电子构建器构建的应用程序显示空白屏幕 - App built using electron-builder in electron-forge + webpack application shows blank screen “Windows 无法访问指定的...”.exe 是由电子包装商或电子锻造制作的 - "Windows cannot access the specified..." .Exe's made by electron-packager nor electron-forge "如何更改电子锻造默认端口?" - How to change electron-forge default port? 电子锻造:缺少一些依赖项 - electron-forge: missing some dependencies @electron-forge/plugin-webpack 中的 configuration.module.rules[2] 问题 - configuration.module.rules[2] Issue in @electron-forge/plugin-webpack electronic-forge:缺少依赖关系= git和node,但是我可以选择哪个git? - electron-forge : Missing dependencies = git and node, but which git can I choose? 电子锻造:据说缺少 git 和节点的依赖关系,但两者都出现在 package.json - electron-forge: Supposedly missing dependencies of git and node but both appear in package.json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM