我使用webpack和TypeScript,似乎d3-tip无法使用webpack.我在鼠标悬停事件上遇到错误
"Uncaught TypeError: Cannot read property 'target' of null".
发生此错误是因为d3-tip模块中的d3.event为null.
我包括如下模块:
const d3: any = require("d3");
d3.tip = require("d3-tip");
Run Code Online (Sandbox Code Playgroud)
但我想d3-did模块中的d3和d3是不同的,这是问题的根源,但我不知道如何解决它.在d3-tip模块中,我们有:
(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) { …Run Code Online (Sandbox Code Playgroud) 我无法包含package.json角度库中的版本,但它可以在项目中使用。我这样使用导入:
import { version } from '../../package.json';
Run Code Online (Sandbox Code Playgroud)
并得到以下错误:
ERROR: error TS6059: File '/Users/.../library/package.json' is not under 'rootDir' '/Users/.../library/src'. 'rootDir' is expected to contain all source files.
An unhandled exception occurred: error TS6059: File '/Users/.../library/package.json' is not under 'rootDir' '/Users/.../library/src'. 'rootDir' is expected to contain all source files.
See "/private/var/folders/tw/z8v0wkt50g5876740n99hzy00000gp/T/ng-0JDpjC/angular-errors.log" for further details.
Run Code Online (Sandbox Code Playgroud)
该途径包括产生安全风险的require整体。仅包含版本号,但适用于角度应用程序而不是库。package.jsonimport { version } from '../../package.json'