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

dagre and dagre-d3 don't work with webpack #129

Open
wolffiex opened this issue Dec 9, 2014 · 11 comments
Open

dagre and dagre-d3 don't work with webpack #129

wolffiex opened this issue Dec 9, 2014 · 11 comments

Comments

@wolffiex
Copy link

wolffiex commented Dec 9, 2014

Webpack would be handy for packaging dagre-d3, but it looks like there's something in the way that the module structure is put together that is breaking it. When I run webpack on a project that includes dagre-d3, I get the following errors. This appears to be related to the code in the /lib files that is like "if (require)..."

[22:05:12] Version: webpack 1.4.13
Asset Size Chunks Chunk Names
main.bundle.js 913110 0 [emitted] main

WARNING in .//dagre-d3/lib/graphlib.js
Critical dependencies:
4:4-11 require function is used in a way, in which dependencies cannot be statically extracted
@ ./
/dagre-d3/lib/graphlib.js 4:4-11

WARNING in .//dagre-d3/lib/lodash.js
Critical dependencies:
4:4-11 require function is used in a way, in which dependencies cannot be statically extracted
@ ./
/dagre-d3/lib/lodash.js 4:4-11

WARNING in .//dagre/lib/graphlib.js
Critical dependencies:
4:4-11 require function is used in a way, in which dependencies cannot be statically extracted
@ ./
/dagre/lib/graphlib.js 4:4-11

WARNING in .//dagre-d3//graphlib/lib/lodash.js
Critical dependencies:
4:4-11 require function is used in a way, in which dependencies cannot be statically extracted
@ .//dagre-d3//graphlib/lib/lodash.js 4:4-11

WARNING in .//dagre/lib/lodash.js
Critical dependencies:
4:4-11 require function is used in a way, in which dependencies cannot be statically extracted
@ ./
/dagre/lib/lodash.js 4:4-11

WARNING in .//dagre//graphlib/lib/lodash.js
Critical dependencies:
4:4-11 require function is used in a way, in which dependencies cannot be statically extracted
@ .//dagre//graphlib/lib/lodash.js 4:4-11

@cpettitt
Copy link
Collaborator

Hey Adam!

Do you have an small example / repro steps I can try?

@rafales
Copy link

rafales commented Jan 6, 2015

Here's a test case:

sudo npm install -g webpack
mkdir example
cd example
mkdir app
echo 'require("dagre-d3")' > app/app.js
npm install dagre-d3
webpack app/app.js dist/

Webpack doesn't like this pattern:

/* global window */

var graphlib;

if (require) {
  try {
    graphlib = require("graphlib");
  } catch (e) {}
}

if (!graphlib) {
  graphlib = window.graphlib;
}

module.exports = graphlib;

@Kepro
Copy link

Kepro commented Apr 15, 2015

@rafales use as alias in resolve in webpack ;)

resolve: {
alias: {
d3: ...
dagre-d3: ...
}
}

@chrisvfritz
Copy link

@Kepro Would you mind being more explicit in how we would use aliases to get rid of these warnings?

@pakdev
Copy link

pakdev commented Aug 14, 2016

I got dagre to work with webpack by forking dagre and graphlib and modifying the bower.js file so that index.js is "main" and the "lib" folder/index.js aren't ignored. This allows webpack to do the bundling vs browserify. Finally, I used the webpack.ProvidePlugin with { dagre: 'dagre' } so I wouldn't have to "require('dagre')" everywhere it's used. When I get a chance, I'll look into making new dagre-webpack and graphlib-webpack packages.

@pakdev
Copy link

pakdev commented Aug 17, 2016

dagre-webpack and graphlib-webpack repos are now published to bower

@raythree
Copy link

raythree commented Mar 5, 2017

Getting the exact same error (above from 1/6/2015) with the current versions when trying to use with react-slingshot which uses Webpack 2.x

@pakdev
Copy link

pakdev commented Mar 5, 2017

Are you using the dagre or dagre-webpack package?

@emailnjv
Copy link

Sorry just getting back to this now. I've tried bower install of dagre-webpack and graphlib-webpack. A usage example of how to get the demos working would be great, showing how to get a reference for:

  var g = new dagreD3.graphlib.Graph().setGraph({});

If I do:

const dagreD3 = require('../../bower_components/dagre-webpack');

Then it has issues resolving graphlib-webpack.

@pakdev
Copy link

pakdev commented Mar 20, 2017

I've updated the README.md for the dagre-webpack project with instructions. Your code looks correct, but I never tried requiring dagre-webpack directly. I've always used the bower-webpack-plugin. Perhaps the plugin automatically 'requires' graphlib-webpack from dagre-webpack's bower.json's dependencies. Did you follow this documentation?

@Y-cookie
Copy link

Will dagre-d3 package with a version above webpack 4 report an error @ @wolffiex

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

9 participants