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

When using Angular2/TypeScript: TypeError: exists is not a function #11

Open
philoliver opened this issue Mar 18, 2017 · 11 comments
Open
Assignees

Comments

@philoliver
Copy link

Hi,
I have an Angular CLI project running in Electron. When I follow your instructions and import the module like this import NFC from '../../../node_modules/nfc-pcsc';, and call const nfc = new NFC(minilogger);, then I get the following error in the console:

TypeError: exists is not a function

And during the build process

WARNING in ./~/bindings/bindings.js
76:22-40 Critical dependency: the request of a dependency is an expression

@philoliver
Copy link
Author

I did some research and found out that the TypeError: exists is not a function appears to be a bug in the node-bindings module. See: TooTallNate/node-bindings#20

It should be fixed when the new release is available on NPM.

However, going one step further, this fix will still not make the it work when using AngularCLI/Webpack. To make it work in this scenario we would need to use node-loader instead of node-bindings to load the binding file.

I did the following change to make it work locally:

"dependencies": {
  "bindings": "github:tootallnate/node-bindings#pull/20/head", < Instead of this,
  "node-loader": "^0.6.0", << use this
  "nan": "^2.5.1"
},

Then edited "/node_modules/@pokusew/pcsclite/lib/pcsclite.js"
const pcsclite = require('node-loader!./../build/Release/pcsclite.node');

@pokusew
Copy link
Owner

pokusew commented Mar 21, 2017

Hi @philoliver

Thank you for posting your problem.

I am quite busy now, but I'll look at it today or tomorrow.

@tobinbc
Copy link

tobinbc commented Apr 2, 2017

Hi @philoliver @pokusew
Just to let you know that I have had exactly the same error and this fixed it also. Currently using a gulp task to search + replace the code post install. Thanks @philoliver for finding the fix!
Cheers

@pokusew pokusew self-assigned this Apr 6, 2017
pokusew added a commit that referenced this issue Sep 9, 2017
@dhruv217
Copy link

Updating the node-binding to 1.3.0 does not seem to have solved the issue as @philoliver pointed out. Is there a permanent solution to this problem instead of using gulp because i am a noob and am not familiar with it.
Thanks for the awesome lib by the was. If not for this I would not be able to make my code platform independent.
I am using an Electron app with angular 4 to read and write data in nfc tags.

@pokusew
Copy link
Owner

pokusew commented Nov 12, 2017

Hi @dhruv217,

I think it should work. Check out Can I use this library in my angular-electron app? in FAQ section of the README. In the linked #24 (comment), there is described what needs to be done in order to make it work.

It is related to the angular-electron boilerplate, but I think, that's what you are using in your project https://github.com/dhruv217/shrabik-smart-card-reader.

Please let me know, if it works for you. If you encounter any problems feel free to contact me. 🙂
I am available for chat here https://discord.gg/bg3yazg.

Hope it helps. 🙂


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

@Canos
Copy link

Canos commented May 4, 2019

@philoliver thanks for your contribution.
After making your changes proposed above i've got this error

Uncaught Error: Cannot open /***/node_modules/@pokusew/pcsclite/build/Release/pcsclite.node: 
TypeError: Cannot read property 'dlopen' of undefined
    at Object.<anonymous> (pcsclite.node:1)
    at Object../node_modules/node-loader/index.js!./node_modules/@pokusew/pcsclite/build/Release/pcsclite.node (vendor.js:72750)
    at __webpack_require__ (bootstrap:78)
    at Object.<anonymous> (pcsclite.js:4)
    at Object../node_modules/@pokusew/pcsclite/lib/pcsclite.js (pcsclite.js:197)
    at __webpack_require__ (bootstrap:78)
    at Object../node_modules/nfc-pcsc/dist/NFC.js (NFC.js:8)
    at __webpack_require__ (bootstrap:78)
    at Object../node_modules/nfc-pcsc/dist/index.js (index.js:145)
    at __webpack_require__ (bootstrap:78)

i'm frozen here, dont know how to continue.
i'm using Angular 7.2 and electron 5.0.1

any idea?

@naveed-31
Copy link

I facing the similar issue ,any update on this issue ??

@ssteiger
Copy link

ssteiger commented Jul 5, 2019

+1 👍

@henrysha
Copy link

Any updates?

@kablin
Copy link

kablin commented May 31, 2021

+1
I try philoliver solution and got

Uncaught Error: node-loader:
TypeError: process.dlopen is not a function

@nmattela
Copy link

nmattela commented Sep 2, 2021

+1
I tried philoliver's solution as well and got:

./node_modules/@pokusew/pcsclite/build/Release/pcsclite.node (./node_modules/node-loader/dist/cjs.js!./node_modules/@pokusew/pcsclite/build/Release/pcsclite.node)
TypeError: this.getOptions is not a function

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

No branches or pull requests

10 participants