首页 > 解决方案 > 升级 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 版本之后,请帮助。

标签: javascriptdebuggingwebpackpreact

解决方案


问题来自一个旧的 eventListener 错误window.addEventListener('error', function(event) {});导致预调试问题,当我删除它时问题解决了


推荐阅读