【发布时间】:2021-05-21 02:04:34
【问题描述】:
首先,我使用 Hugo、Webpack、Babel 和 nodeJS。 现在一切都在编译,但我得到了一些控制台错误。
我在 Chrome localhost 控制台中遇到的相关错误:
bundle.js:2 Uncaught TypeError: Cannot read property 'style' of undefined
at bundle.js:2
at Object.671 (bundle.js:2)
at n (bundle.js:2)
at Module.150 (bundle.js:2)
at n (bundle.js:2)
at bundle.js:2
at bundle.js:2
我在 Firefox localhost 控制台中遇到的相关错误:
Uncaught TypeError: t[e] is undefined
671 http://localhost:1313/assets/js/bundle.js:2
671 http://localhost:1313/assets/js/bundle.js:2
n http://localhost:1313/assets/js/bundle.js:2
150 http://localhost:1313/assets/js/bundle.js:2
n http://localhost:1313/assets/js/bundle.js:2
<anonymous> http://localhost:1313/assets/js/bundle.js:2
<anonymous> http://localhost:1313/assets/js/bundle.js:2
未定义的示例:
(function (e) {
'use strict';
let t = document.getElementsByClassName('bstTab');
t[e].style.display = 'block',
0 === e ? (document.getElementById('prevBstBtn').style.display = 'none', document.getElementById('nextBstBtn').style.visibility = 'visible') : document.getElementById('prevBstBtn').style.display = 'inline',
e === t.length - 1 ? (document.getElementById('nextBstBtn').style.visibility = 'hidden', document.getElementById('ppBstBtn').type = 'image') : (document.getElementById('nextBstBtn').innerHTML = 'Next', document.getElementById('ppBstBtn').type = 'hidden'),
function (e) {
let t,
n = document.getElementsByClassName('step');
for (t = 0; t < n.length; t++) n[t].className = n[t].className.replace(' active', '');
n[e].className += ' active'
}(e)
}) (0),
这是来自 localhost 控制台链接的 bundle.js 的源代码。
进入捆绑包之前的实际功能:
function showBstTab(n) {
//alert(n);
// This function will display the specified tab of the form ...
"use strict";
let x = document.getElementsByClassName("bstTab");
x[n].style.display = "block";
// ... and fix the Previous/Next buttons:
if (n === 0) {
document.getElementById("prevBstBtn").style.display = "none";
document.getElementById("nextBstBtn").style.visibility = 'visible';
} else {
document.getElementById("prevBstBtn").style.display = "inline";
}
if (n === (x.length - 1)) {
document.getElementById("nextBstBtn").style.visibility = 'hidden';
//nextBtn.type ="hidden";
document.getElementById("ppBstBtn").type = "image";
} else {
document.getElementById("nextBstBtn").innerHTML = "Next";
document.getElementById("ppBstBtn").type = "hidden";
}
// ... and run a function that displays the correct step indicator:
fixBstStepIndicator(n);
}
【问题讨论】:
-
听起来你没有找到元素
-
对,但我该如何解决呢?
-
html 模块是否需要与它捆绑在一起?还是我需要将 bundle.js 链接到 htmls?类似的东西。现在我有从 head.html 调用的捆绑脚本,但不是 html 模块
-
感谢工作。 @epascarello
标签: javascript node.js webpack bundle hugo