问题
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