Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught Exception: Error: Cannot find module 'pcsclite' #20

Open
flackjap opened this issue Feb 20, 2019 · 3 comments
Open

Uncaught Exception: Error: Cannot find module 'pcsclite' #20

flackjap opened this issue Feb 20, 2019 · 3 comments
Labels

Comments

@flackjap
Copy link

flackjap commented Feb 20, 2019

Hi,

This is the first time I'm building something with Electron.
Now, I read everything there is in the FAQ section and "Can I use this library in my Electron app?".
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 installing everything a few times.

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)

Sorry if I shouldn't post this here if this is the general problem with building native modules. I just cannot know if it is, since 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.

Thanks in advance.

--

edit/update: Also tried manually copying the "pcsclite.node" from node_modules/@pokusew/pcsclite/build/Release" into the build folder of the project - still getting the same error.

@flackjap flackjap changed the title Uncaught Exception: Error: Cannot find module 'pcsclite Uncaught Exception: Error: Cannot find module 'pcsclite' Feb 21, 2019
@pokusew
Copy link
Owner

pokusew commented Feb 21, 2019

Hi @flackjap,

Thank you for posting your issue here. 🙂

I think, it's caused by incorrect module name in require statement.
The correct way to import @pokusew/pcsclite is:

const pcsclite = require('@pokusew/pcsclite');

The module name must exactly match the name listed in package.js's dependencies section.

Please let me know if you are able to make it work with the change above.

BTW: Unfortunately, there was a mistake (missing @pokusew scope) in the require statement in the README's example. I am very, very, very sorry for the confusion it might have created. 😔I've just fixed it and released the new version (so that it's fixed on npm README, too). 🚀

BTW 2: 👀I highly recommend taking a look at nfc-pcsc which offers easy to use high level API for detecting / reading and writing NFC tags and cards. ✨It is much easier to work with, it has more documentation and more examples. (And it uses @pokusew/pcsclite under the hood.)

Hope it helps. 🙂


PS Don't forget to star ⭐️my nfc-pcsc library, if you find it useful. 😃Thanks.

@flackjap
Copy link
Author

flackjap commented Feb 25, 2019

Hi @pokusew ,

Yup, that was the issue :)
I figured it out by myself about 10 minutes before you commented. Someone asked me to post the code on StackOverflow (where I also posted a question about this), and I asked myself "What could possibly go wrong in the code - I just copy/pasted from readme and it only gets stuck at the import/require level" - and voila, there it was. I thought that I could even swear that I have already tried changing it to "@pokusew/pcsclite" - but it looks like I didn't :) ... Probably got distracted by thinking that the problem has to be around compiling native modules and totally neglected something basic as this :)

Thanks for the recommendation about the nfc-pcsc, I will definitely take a look at it and give it a shot.

Cheers!

@rc201612
Copy link

rc201612 commented May 26, 2019

Hi @pokusew

I notice you say that you have this library working with Electron.

I am currently getting the the "cannot find module" error.

image

Before this I was getting the NODE_MODULE_VERSION mismatch error and ended up running ./node_modules/.bin/electron-rebuild . This suggests that it was finding the module before I ended up rebuilding it. I am running Windows and passed the --windows flag into the build.

Below is the code that I have in my Electron app.

const pcsclite = require('@pokusew/pcsclite');

const pcsc = pcsclite();

pcsc.on('reader', (reader) => {

  console.log('New reader detected', reader.name);

});

pcsc.on('error', err => {
  console.log('PCSC error', err.message);
});

Do you think you'd be able to share a simple example of running this inside Electron?

Many thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants