javascript - 升级 Preact 版本后调试无法正常工作
问题描述
我在调试我的 preact 项目时遇到了一些问题,大多数 js 错误也没有出现在控制台中。
例如,我将此代码添加到我的组件中:
<button onClick={() => {
const someVar = someUnknownVariable;
}}>
fire error
</button>
当我点击按钮时没有出现错误,说 someUnknownVariable 没有定义,其他 js 错误也没有出现。
这是我的 preact.config.js 文件:
import compose from 'lodash.compose';
export default (config, env, helpers) => {
return compose(addEmotionPlugin, configRules)(config, env, helpers);
};
function addEmotionPlugin(config) {
let babel = config.module.rules.filter(loader => loader.loader === 'babel-loader')[0]
.options;
babel.plugins.push([
'emotion',
{
hoist: true,
sourceMap: false,
autoLabel: true,
labelFormat: '[local]',
extractStatic: false,
outputDir: '',
},
]);
return config;
}
function configRules(config, env) {
if (env.isProd) {
config.devtool = 'source-map';
config.output.filename = '[name].js';
config.output.publicPath = process.env.NODE_ASSETS || '/';
}
return config;
}
在我的 index.js 文件中,我在开头有这段代码。
if (process.env.NODE_ENV==='development') {
require("preact/debug");
}
这发生在我升级 preact 版本之后,请帮助。
解决方案
问题来自一个旧的 eventListener 错误window.addEventListener('error', function(event) {});
导致预调试问题,当我删除它时问题解决了
推荐阅读
- windows - Windows(所有版本):选中/取消选中上下文菜单中的多个选项而无需多次右键单击?
- c - 进程在 C 中返回 -1073741819 (0xC0000005)
- typescript - TypeScript:如何从另一个界面合并对象?
- html - 如何水平对齐两个父级(1个共同父级和1个唯一)内部的2个div?
- c# - CefSharp WPF 崩溃
- php - 使用带前导零的最大和最小长度的数字范围生成器
- selenium-chromedriver - getText() 和 getFirstSelectedOption().getText() 没有给出预期的文本
- aws-lambda - 使用 AWS lambda 将 CMYK 图像替换为 RGB
- python-3.x - 如何将音频映射到目标文本转录
- javascript - 如何在 react native 和 redux 应用程序中处理 JWT 令牌到期