How do I implement a nfc reader (ACR122) to an Ele

2019-08-21 11:19发布

问题:

I have downloaded this library (https://github.com/pokusew/nfc-pcsc) and now i'm trying to run an Electron project in it, but is giving me everytime problems when i try to run it as an Electron project. So my question is: How can I implement this library on my Electron project and make it work not as node.js

I tried to npm install --save electron@latest in the library and change on the json the script "example": "node -r @babel/register examples/read-write.js" to "example": "electron -r @babel/register examples/read-write.js" also i have tried to uninstall and install, i have done electron-rebuild

    "rebuild": "electron-rebuild -f -w yourmodule",
    "build": "babel src --out-dir dist",
    "example": "electron -r @babel/register examples/read-write.js",
    "example-basic": "node -r @babel/register examples/basic.js",
    "example-from-readme-3": "node -r @babel/register examples/from-readme-3.js",
    "example-led": "node -r @babel/register examples/led.js",
    "example-mifare-classic": "node -r @babel/register examples/mifare-classic.js",
    "example-mifare-desfire": "node -r @babel/register examples/mifare-desfire.js",
    "example-mifare-ultralight-ntag": "node -r @babel/register examples/mifare-ultralight-ntag.js",
    "example-ndef": "node -r @babel/register examples/ndef.js",
    "example-uid-logger": "node -r @babel/register examples/uid-logger.js",
    "example-without-auto": "node -r @babel/register examples/without-auto.js",
    "prepack": "yarn build && yarn test",
    "test": "cross-env NODE_ENV=test ava test/tests.js --verbose"
  } 

I'm getting this error when i'm trying to run the app as Electron app (https://i.imgur.com/UhSjlo6.png) and when i do the rebuild i have this error: × Rebuild Failed An unhandled error occurred inside electron-rebuild

回答1:

Electron as of v5.0.0 is using Node.js v12.0.0. This native module (nfc-pcsc) is not building correctly for that version.

Downgrade Electron to v4, rebuild via "electron-rebuild" and it should build properly.

npm install --save-dev electron@4.2.2

then

electron-rebuild