d3-tip npm模块不能使用browserify [英] d3-tip npm module not working with browserify

查看:146
本文介绍了d3-tip npm模块不能使用browserify的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我用 npm install d3-tip v0.6.7安装d3-tip,然后browserify我的项目没有任何问题。

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

我的js如下所示

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>";
              });

我得到的错误是:

TypeError: d3 is undefined in my bundle.js yet

I在我的代码中的其他地方使用d3没有问题,这让我相信错误是在npm模块d3提示,但我可能是错误的。

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.

任何想法? p>

Any ideas?

推荐答案

我发现你的问题,这是完全相同的问题,我试过了很多东西,我发现你可以传递参数

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);

然后你可以像以前一样调用d3tip。

And then you can call d3tip as you already have.

这篇关于d3-tip npm模块不能使用browserify的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆