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

ES6 import fails #60

Closed
alexhochreiter opened this issue Jul 20, 2017 · 5 comments
Closed

ES6 import fails #60

alexhochreiter opened this issue Jul 20, 2017 · 5 comments

Comments

@alexhochreiter
Copy link

I'm trying to import the library via an ES6 import statement import InstaScan from 'instascan', which throws the following error:

ERROR in ./node_modules/instascan/src/zxing.js
Module not found: Error: Can't resolve 'fs' in 'C:\projects\my_project\node_modules\instascan\src'
 @ ./node_modules/instascan/src/zxing.js 4:725-738 4:313578-313591
 @ ./node_modules/instascan/src/scanner.js
 @ ./node_modules/instascan/index.js
 @ ./src/components/qrcode-scanner.component.js
 @ ./stories/qrcode-scanner.component.story.js
 @ ./stories/index.js
 @ ./.storybook/config.js

Is it just my npm setup beeing all messed up again, or is this lib not intended to be used that way?
Probably this is just webpack messing things up...

To reproduce create a simple react based app with one of the create-react-scripts, start the dev server and try to import and/or require it from there.

Windows 10 1607 build 14393.1480
Npm 5.03
The npm module fs is installed globally and locally in the project's folder.

@ghost
Copy link

ghost commented Jul 21, 2017

I encountered this issue in react too. I managed to get it working using find/replace in instascan/src/zxing.js. Find the 2 phrases below and replace both with empty strings.

var fs=require("fs");
var nodeFS=require("fs");

I'm honestly not very familiar with zxing.js so I don't know why this works.

@alexhochreiter
Copy link
Author

Not sure why webbrowser targeted libs should make any use of 'fs' but your absolutely right that this was the problem!
Thank you very much for this!
Is it appropiate to make a PR for this or will @schmich take this into account?

@ssc-hrep3
Copy link

Unfortunately, this library breaks my webpack build process (same issue as above). The hack of @rshepp works, but is very impractical when working with multiple people on a project.

@axed Can you make a PR? That would be great :)

@raphox
Copy link

raphox commented Aug 11, 2017

add this to your webpack config:

module.exports = {
  node: {
    fs: "empty"
  },
  entry: {
    app: [
      './src/main.js'
    ]
  },
...

Like in pugjs/pug-loader#8 (comment)

@danjanny
Copy link

add this to your webpack config:

module.exports = {
  node: {
    fs: "empty"
  },
  entry: {
    app: [
      './src/main.js'
    ]
  },
...

Like in pugjs/pug-loader#8 (comment)

alhamdulillah bisa :)

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

No branches or pull requests

4 participants