d3-tip npm module not working with browserify

女生的网名这么多〃 提交于 2020-01-04 06:53:07

问题


First I installed d3-tip with npm install d3-tip v0.6.7 then browserify'd my project without any issues.

My js looks like the following

var d3 = require("d3");
var d3tip = require("d3-tip");

    var tip = d3tip()
              .attr('class', 'd3-tip')
              .offset([-10, 0])
              .html(function(d) {
                return "<strong>Hello World:</strong>";
              });

The error I get is:

TypeError: d3 is undefined in my bundle.js yet

I'm using d3 elsewhere in my code without issue which makes me believe the error is in the npm module for d3 tip but I could be wrong.

Any ideas?


回答1:


I found your question and it was the exact same problem I had, after trying a lot of things I found that you can pass arguments to require.

I solved my problem using:

var d3 = require("d3");
var d3tip = require('d3-tip')(d3);

And then you can call d3tip as you already have.



来源:https://stackoverflow.com/questions/35067167/d3-tip-npm-module-not-working-with-browserify

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!