问题描述
我正在尝试使用这样的 ES6 模块实现 PlotlyJS():
索引.html
<script src="main.js" type="module"></script>
主文件
import * as Plotly from './plotly.js';
但是我有这个错误“未捕获的类型错误:无法读取 plotly.js 中未定义的属性‘文档’”
plotly.js:21576 Uncaught TypeError: Cannot read property 'document' of undefined
at plotly.js:21576
at Object.151 (plotly.js:31122)
at o (plotly.js:7)
at plotly.js:7
at Object.699.../constants/numerical (plotly.js:102912)
at o (plotly.js:7)
at plotly.js:7
at Object.1.../src/lib (plotly.js:10)
at o (plotly.js:7)
at plotly.js:7
问题出在图书馆,我想。 任何的想法?
1楼
Wolfgang Kuehn
0
2019-03-29 13:50:25
这是一个错误
你必须等待 plotly.js Version 2.0 或根据 opener 修复它
我通过从 }(); 更改第 27724 行来修复它。 到 }.apply(self); 但这只是一个黑客:)
当然,确切的线是一个移动目标,具体取决于您使用的情节发布。
2楼
Vinod Louis
0
2021-05-21 03:24:43
如果有人想在 node_module 中实现更改并使用更激进的方法,请利用实用程序。
在 package.json 脚本中,可以使用以下命令来修补 node_modules
"postinstall": "./node_modules/.bin/patch-package"
plotly 1.58.4 的补丁
diff --git a/node_modules/plotly.js/dist/plotly-with-meta.js b/node_modules/plotly.js/dist/plotly-with-meta.js
index 1aaac5a..cb3ecfe 100644
--- a/node_modules/plotly.js/dist/plotly-with-meta.js
+++ b/node_modules/plotly.js/dist/plotly-with-meta.js
@@ -35864,7 +35864,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
return request.responseXML;
});
if (typeof define === "function" && define.amd) this.d3 = d3, define(d3); else if (typeof module === "object" && module.exports) module.exports = d3; else this.d3 = d3;
-}();
+}.apply(self);
},{}],170:[function(_dereq_,module,exports){
module.exports = function () {
for (var i = 0; i < arguments.length; i++) {
diff --git a/node_modules/plotly.js/dist/plotly.js b/node_modules/plotly.js/dist/plotly.js
index 365230c..6268511 100644
--- a/node_modules/plotly.js/dist/plotly.js
+++ b/node_modules/plotly.js/dist/plotly.js
@@ -35864,7 +35864,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
return request.responseXML;
});
if (typeof define === "function" && define.amd) this.d3 = d3, define(d3); else if (typeof module === "object" && module.exports) module.exports = d3; else this.d3 = d3;
-}();
+}.apply(self);
},{}],170:[function(_dereq_,module,exports){
module.exports = function () {
for (var i = 0; i < arguments.length; i++) {
d3 3.5.17 补丁
diff --git a/node_modules/d3/d3.js b/node_modules/d3/d3.js
index aded45c..d5b3cad 100644
--- a/node_modules/d3/d3.js
+++ b/node_modules/d3/d3.js
@@ -9551,4 +9551,4 @@
return request.responseXML;
});
if (typeof define === "function" && define.amd) this.d3 = d3, define(d3); else if (typeof module === "object" && module.exports) module.exports = d3; else this.d3 = d3;
-}();
\ No newline at end of file
+}.apply(self);