模块 '"../node_modules/@types/d3"' 没有导出成员 'event'
Module '"../node_modules/@types/d3"' has no exported member 'event'
我有 2 个包版本相似的 pbiviz 项目。
"dependencies": {
"@babel/runtime": "7.6.0",
"@babel/runtime-corejs2": "7.6.0",
"@types/d3": "5.7.2",
"d3": "5.12.0",
"powerbi-visuals-utils-dataviewutils": "2.2.1",
"powerbi-visuals-api": "~2.6.1",
"core-js": "3.2.1"
}
旧项目从 d3
完美导入 event
。但是新项目显示这个错误。
Module '"../node_modules/@types/d3"' has no exported member 'event'.ts(2305)
在搜索解决方案和其他尝试(如删除和 运行 npm i
失败后,我只是将 'node_modules/@types' 文件夹从旧项目复制粘贴到新项目,它成功了。
如果有人知道导致此问题的原因和正确的解决方案,请分享。
event
是 d3-selection 的一部分,仅在 @types/d3-selection
的 v1
中导出。 运行 yarn list
/npm list
,你会看到d3-selection的"@types/d3": "5.7.4"
依赖是@types/d3-selection@*
,实际上默认是v2
。
screenshot of @types/d3 dependency list
解决方案是在依赖项中包含 "@types/d3-selection": "^1.0.0"
我刚刚更新了 D3js 和类型,
npm i d3@latest @types/d3@latest
这解决了问题。现在event
是事件监听回调函数的第一个参数
我有 2 个包版本相似的 pbiviz 项目。
"dependencies": {
"@babel/runtime": "7.6.0",
"@babel/runtime-corejs2": "7.6.0",
"@types/d3": "5.7.2",
"d3": "5.12.0",
"powerbi-visuals-utils-dataviewutils": "2.2.1",
"powerbi-visuals-api": "~2.6.1",
"core-js": "3.2.1"
}
旧项目从 d3
完美导入 event
。但是新项目显示这个错误。
Module '"../node_modules/@types/d3"' has no exported member 'event'.ts(2305)
在搜索解决方案和其他尝试(如删除和 运行 npm i
失败后,我只是将 'node_modules/@types' 文件夹从旧项目复制粘贴到新项目,它成功了。
如果有人知道导致此问题的原因和正确的解决方案,请分享。
event
是 d3-selection 的一部分,仅在 @types/d3-selection
的 v1
中导出。 运行 yarn list
/npm list
,你会看到d3-selection的"@types/d3": "5.7.4"
依赖是@types/d3-selection@*
,实际上默认是v2
。
screenshot of @types/d3 dependency list
解决方案是在依赖项中包含 "@types/d3-selection": "^1.0.0"
我刚刚更新了 D3js 和类型,
npm i d3@latest @types/d3@latest
这解决了问题。现在event
是事件监听回调函数的第一个参数