dagrejs / dagre-d3

A D3-based renderer for Dagre
MIT License
2.86k stars 591 forks source link

Not able to use with requireJs #246

Open arun-kahuna opened 8 years ago

arun-kahuna commented 8 years ago

Please fix the define functionality for dagre-d3 to with with requireJs. I see three issues : Issue 1. When including requirejs library above dagre-d3.js library in the browser like :

 <script src="lib/require.js"></script>
 <script src="node_modules/dagre-d3/dist/dagre-d3.js" ></script>

I am getting following error in console : require.js:165 Uncaught Error: Mismatched anonymous define() module: function (){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

Issue 2. Not able to use directly with requireJS like 👍

config = {
        name: 'src/app',
        baseUrl: ".",
        out: 'dist/app.build.js',
        paths: {
            "jquery": "lib/jquery-1.12.0",
            "underscore": "lib/underscore",
            "dagre-d3": "node_modules/dagre-d3/dist/dagre-d3"
        }
};

I am getting same above error in console when i try to add dagre-d3 as a dependency like :

require(['lib/modules/template','dagre-d3'], function(template,d) {
  console.log(d);
  template.showName("Arun");
});

Also, tried adding a shim. Its not working with gulp-requirejs. Please take a look at : https://github.com/arun-kahuna/shim-not-working

Issue 3: Even in a simple html file, if we include require.js first and then include dagre-d3.js, its blowing up the the browser with the same error : Uncaught Error: Mismatched anonymous define()

We are not having this issue if we load dagre-d3 first and then requireJS. But in my application, requireJS is loaded first and then the following code in dagre-d3 : typeof define==="function"&&define.amd){define([],f)

is throwing the same error.

For now, i have to add false to the condition to not to execute : define([],f) like

else if(false && typeof define==="function"&&define.amd){define([],f)}

Then dagre-d3 can load after requirejs library on the same page.

patterson commented 6 years ago

I'm seeing this same error. Any updates on this?

rjkat commented 4 years ago

+1