I am using webpack and TypeScript and it seems that d3-tip cannot work with webpack. I get an error on mouse events of "Uncaught TypeError: Cannot read property 'target' of null" .
This error occurs because d3.event in the d3-tip module is null.
I include modules as follows:
const d3: any = require("d3"); d3.tip = require("d3-tip");
but I think the d3 and d3 in the d3-tip module are different and this is the source of the problems, but I don’t know how to solve it. In the d3-tip module we have:
(function (root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module with d3 as a dependency. define(['d3'], factory) } else if (typeof module === 'object' && module.exports) { // CommonJS var d3 = require('d3') module.exports = factory(d3) } else { // Browser global. root.d3.tip = factory(root.d3) } }(this, function (d3) { ...
And it compiles webpack into
function(module, exports, __webpack_require__) { var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// d3.tip // Copyright (c) 2013 Justin Palmer // // Tooltips for d3.js SVG visualizations (function (root, factory) { if (true) { // AMD. Register as an anonymous module with d3 as a dependency. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(465)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) } else if (typeof module === 'object' && module.exports) { // CommonJS var d3 = require('d3') module.exports = factory(d3) } else { // Browser global. root.d3.tip = factory(root.d3) } }(this, function (d3) { ... ( function(module, exports, __webpack_require__) { var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// d3.tip // Copyright (c) 2013 Justin Palmer // // Tooltips for d3.js SVG visualizations (function (root, factory) { if (true) { // AMD. Register as an anonymous module with d3 as a dependency. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(465)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) } else if (typeof module === 'object' && module.exports) { // CommonJS var d3 = require('d3') module.exports = factory(d3) } else { // Browser global. root.d3.tip = factory(root.d3) } }(this, function (d3) { ... , __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' (__WEBPACK_AMD_DEFINE_FACTORY __ apply (exports, __WEBPACK_AMD_DEFINE_ARRAY__)):?. __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ == undefined && (! function(module, exports, __webpack_require__) { var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// d3.tip // Copyright (c) 2013 Justin Palmer // // Tooltips for d3.js SVG visualizations (function (root, factory) { if (true) { // AMD. Register as an anonymous module with d3 as a dependency. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(465)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) } else if (typeof module === 'object' && module.exports) { // CommonJS var d3 = require('d3') module.exports = factory(d3) } else { // Browser global. root.d3.tip = factory(root.d3) } }(this, function (d3) { ...
and obviously what AMD is using. If I could get a factory d3-tip, I would solve this problem.