pokusew / nfc-pcsc

Easy reading and writing NFC tags and cards in Node.js
MIT License
531 stars 131 forks source link

Problem with angular-electron? #24

Closed drajvver closed 7 years ago

drajvver commented 7 years ago

Hello, I've got empty angular-electron app and wanted to add NFC to it. The problem is that when I copy the first example to HomeComponent I can't compile it.

ERROR in vendor.bundle.js from UglifyJs Unexpected token: name (ACR122Reader) error comes out, any ideas?

Additionally this happens whenI try to run in dev mode. I'm using the newest electron and nodejs.

pokusew commented 7 years ago

Hi @drajvver,

I'll sum up (just for the evidence) what we discussed and found out during our chat:

  1. According to the angular-electron documentation – Use NodeJS Native libraries:

    If you need to use NodeJS native libraries, you MUST add it manually in the file webpack.config.js in root folder ...

    So in this case you need to add "nfc-pcsc": "require('nfc-pcsc')" in the webpack.config.js externals section (for example below https://github.com/maximegris/angular-electron/blob/master/webpack.config.js#L226).

  2. Don't forget that you need to rebuild the native modules for Electron.

    You can do it for example by changing build:electron:main script in the package.json to the following:

     "tsc main.ts --outDir dist && copyfiles package.json dist && cd dist && npm install --target=1.7.5 --arch=x64 --target_arch=x64 --disturl=https://atom.io/download/electron --runtime=electron --build-from-source=true --prod && cd .."

    After that, don't forget to delete the dist folder and re-run npm start and npm electron:serve.

    Just note that's not the only solution. 🙂

With the changes

Hope it helps. 🙂


9th September 2017: I updated the comment with the fixed script and closed the issue, as the solution works. I also add note to the project README.


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

Canos commented 5 years ago

There is no webpack.config.js in recent versions of angular (as of 6.0).
So how can we configure nfc-pcsc in angular +6?