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

webpack compile fail, require('fs'), module not found #83

Closed
li-yinan opened this issue Apr 13, 2017 · 2 comments
Closed

webpack compile fail, require('fs'), module not found #83

li-yinan opened this issue Apr 13, 2017 · 2 comments

Comments

@li-yinan
Copy link

li-yinan commented Apr 13, 2017

viz does check running environment. when running in node envrionment viz require('fs').
I use viz in browser, but the require('fs') is still there, webpack can't find fs module and compile fail
How can I use viz with webpack?

@mdaines
Copy link
Owner

mdaines commented Apr 13, 2017

I was looking at this recently and found two possible solutions:

  1. Ask webpack to replace "fs", etc. with empty objects.
  // ...

  node: {
    fs: "empty",
    path: "empty",
    crypto: "empty"
  },

 // ...

It looks like Viz.js could use the "browser" field in package.json to do this: https://github.com/defunctzombie/package-browser-field-spec

  1. Use script-loader:
import vizScriptLoader from 'script-loader!viz.js';

mdaines added a commit that referenced this issue Apr 16, 2017
This indicates that the "fs", "path", and "crypto" packages should be empty objects in a browser context, since they aren't actually required in that case even though require statements are present. This prevents webpack, etc. from trying to include them. Addresses #83.
@mdaines
Copy link
Owner

mdaines commented Apr 16, 2017

The next release will include a "browser" property in package.json that appears to address this problem.

@mdaines mdaines closed this as completed Apr 16, 2017
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

2 participants