Giter Club home page Giter Club logo

Comments (5)

pokusew avatar pokusew commented on September 2, 2024

Hi @haakonmt,

thank you for posting your issue.

I personally use nfc-pcsc inside an Electron app which is built using Webpack and it works great, but it requires some config (in some cases):

  1. if you use Webpack (create-react-app uses it), you need to add nfc-pcsc to externals section in webpack.config.js (it is because it cannot be loaded and built with Webpack as it loads Node native modules)

    {
      // ... your Webpack object
      externals: ['nfc-pcsc']
    }
  2. be aware of Node Native modules usage in Electron, see FAQ Can I use this library in my Electron app? in README (it might work out of box, but in most cases you need to rebuild modules)

I hope you will be able to make it work with these info. 🙂

However, if you get stuck, you can create repo with your code (it can be just a minimal example), where the issue occurs and I'll take a look at it (clone, install, run).

Hope it helps.

from nfc-pcsc.

haakonmt avatar haakonmt commented on September 2, 2024

Thank you for the fast response!

Adding the library to webpack's externals seems like a perfectly good solution, but I forgot to add that I would try to avoid ejecting if possible.

Nevertheless, I found a solution! By using window.require to import the nfc module (const { NFC } = window.require('nfc-pcsc');), I was able to make webpack ignore it altogether, while still making it work in a node environment (in my case electron).

from nfc-pcsc.

Ionut-Milas avatar Ionut-Milas commented on September 2, 2024

@haakonmt How did you managed to get this running with React without eject ?
Where did you required the files ?

from nfc-pcsc.

haakonmt avatar haakonmt commented on September 2, 2024

@Ionut-Milas Wherever you want! For instance in src/nfc.js:

const { NFC } = window.require('nfc-pcsc');

const nfc = new NFC();

nfc.on('reader', reader => {
    ...
});

Then at the top of src/index.js: import './nfc';

from nfc-pcsc.

Ionut-Milas avatar Ionut-Milas commented on September 2, 2024

Thanks a lot !

from nfc-pcsc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.