我已经安装了d3": "^3.5.17"
and "d3-tip": "^0.7.1"
使用 npm (d3-tip 文档 https://www.npmjs.com/package/d3-tip)。然后在我的index.js
文件我有这个代码:
var d3 = require('d3');
var d3tip = require('d3-tip')(d3);
console.log('d3 version', d3.version);
var tip = d3tip().attr('class', 'd3-tip').html(function(d) { return "hello world"; })
但是当我使用 browserify 构建索引文件并将其加载到浏览器中时,我看到一个错误var tip
line:
index.js:247 Uncaught TypeError: Cannot read property 'node' of undefined
这是来自 d3-tip 源代码中的这个函数:
function getSVGNode(el) {
el = el.node()
if(el.tagName.toLowerCase() === 'svg')
return el
return el.ownerSVGElement
}
看起来这个函数正在等待一个节点传递给它?但这从哪里来呢?
构建本身不会抛出任何错误,并且我认为我正确地需要 d3-tip ,根据这个问题 https://stackoverflow.com/questions/35067167/d3-tip-npm-module-not-working-with-browserify。正如预期的那样,控制台语句显示 d3 版本为 3.5.17。
更新:这是我的package.json
file:
{
"name": "myapp",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"watch": "watchify index.js -o main.js --debug --verbose",
"build": "browserify index.js | uglifyjs > main.min.js"
},
"dependencies": {
"d3": "^3.5.17",
"d3-tip": "^0.7.1",
"datatables.net": "^1.10.12",
"datatables.net-bs": "^1.10.12"
},
"devDependencies": {
"uglifyjs": "^2.4.10",
"watchify": "^3.2.1"
}
}
我安装了文件npm install
.