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

"Failed to minify code" (create-react-app) #27

Closed
haakonmt opened this issue Sep 21, 2017 · 5 comments
Closed

"Failed to minify code" (create-react-app) #27

haakonmt opened this issue Sep 21, 2017 · 5 comments
Assignees
Labels

Comments

@haakonmt
Copy link

I'm trying to use this library together with resin.io's electron + react template, which uses create-react-app.

When I run the build script it fails telling me that this library (specifically dist/Reader.js) can't be minified and directs me to this link, which suggests filing an issue on the dependency in question, so here I am.

Native node modules + create-react-app + electron is asking for trouble, I know, but maybe you have some suggestions?

@pokusew pokusew self-assigned this Sep 22, 2017
@pokusew
Copy link
Owner

pokusew commented Sep 22, 2017

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.

@haakonmt
Copy link
Author

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).

@Ionut-Milas
Copy link

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

@haakonmt
Copy link
Author

haakonmt commented Jul 27, 2018

@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';

@Ionut-Milas
Copy link

Thanks a lot !

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