node.js - Uncaught Exception: Error: Cannot find module 'pcsclite'
问题描述
This is the first time I'm building something with Electron. Now, I read everything there is in the FAQ section of this module (node-pcsclite) and the "Can I use this library in my Electron app?" section. I tried everything from the Electron docs (Using Native Node Modules). The only thing I didn't try is "Manually building for a custom build of Electron" - since I'm not running a custom Electron build.
Things I tried:
- Different versions of almost everything.
- Tried doing everything on OSX and Linux.
- Older node and npm versions.
- Different electron headers.
- Checked that the cpu target architectures are matched.
- Tried packaging the app with electron-builder and running it on OSX.
- Tried re-configuring the electron-builder with options such as buildDependenciesFromSource and npmRebuild set to true.
- Removed node_modules, removed cache and tried re-installing everything a few times.
- Tried manually copying the "pcsclite.node" from node_modules/@pokusew/pcsclite/build/Release" into the build folder of the project and repackaging it again - still getting the same error.
No success. I keep getting the following Uncaught Exception whenever I run the app (whether with "electron ." (npm start) or as a fully packaged app with electron-builder).
Error: Cannot find module 'pcsclite'
at Module._resolveFilename (internal/modules/cjs/loader.js:584:15)
at Function.Module._resolveFilename (/Users/flackjap/Code/vozzi/electronic-service-book/first-test/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/common/reset-search-paths.js:43:12)
at Function.Module._load (internal/modules/cjs/loader.js:510:25)
at Module.require (internal/modules/cjs/loader.js:640:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/Users/flackjap/Code/vozzi/electronic-service-book/first-test/main.js:4:18)
at Object.<anonymous> (/Users/flackjap/Code/vozzi/electronic-service-book/first-test/main.js:144:3)
at Module._compile (internal/modules/cjs/loader.js:693:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:704:10)
at Module.load (internal/modules/cjs/loader.js:602:32)
I'm not sure if this is the general problem with building native modules or just a problem with this module specifically. I tried googling and didn't find enough relatable issues, so it seemed to me that the problem might actually be with this module specifically.
This is my package.json:
"name": "electron-quick-start",
"version": "1.0.0",
"description": "A minimal Electron application",
"main": "main.js",
"scripts": {
"start": "electron .",
"pack": "electron-builder --dir",
"distt": "electron-builder",
"dist": "build"
},
"repository": "https://github.com/electron/electron-quick-start",
"keywords": [
"Electron",
"quick",
"start",
"tutorial",
"demo"
],
"author": "GitHub",
"license": "CC0-1.0",
"devDependencies": {
"electron-builder": "^20.38.5",
"electron-rebuild": "^1.8.4"
},
"dependencies": {
"electron": "^4.0.4",
"@pokusew/pcsclite": "^0.5.1"
},
"build": {
"buildDependenciesFromSource": true,
"nodeGypRebuild": false,
"npmRebuild": true,
"appId": "electron.vozzi.app",
"dmg": {
"contents": [
{
"x": 110,
"y": 150
},
{
"x": 240,
"y": 150,
"type": "link",
"path": "/Applications"
}
]
},
"linux": {
"target": [
"AppImage",
"deb"
]
},
"win": {
"target": "squirrel",
"icon": "build/icon.ico"
}
}
}
The only thing I find a bit suspicious is the folder structure for this module, since it has two parent folders (node_modules/@pokusew/pcsclite/...), and that maybe some paths are misconfigured, but I don't know where to look or how to debug. I did however see at some Stackoverflow comments that people are manually configuring some module paths in some cases, but I'm not sure how should I approach this, or even if I should be doing that.
解决方案
推荐阅读
- excel - 更新单词书签内的图形/表格
- php - 通过 PHP 将保存在 Desktop 文件夹中的文件链接到已存在的项目列表
- node.js - 无法从 opencv4nodejs 读取 h264 中的 UDP 网络流
- python - 如何解析嵌套 json 对象的元素?
- css - 如何将 CSS 文件内容导入 Javascript 变量
- c# - SSIS脚本任务中的C#脚本将“文本”格式的Excel列转换为“常规”
- php - 当我尝试从 sql server 获取 DataTime 时出现问题
- java - 引起:java.lang.NoSuchMethodError: sun.reflect.misc.ReflectUtil.newInstance(Ljava/lang/Class;)Ljava/lang/Object;
- swift - 在 alamofire 中通过 POST 传递复杂参数
- javascript - img.onload 在 Internet Explorer 11 中不起作用