升级 Preact 版本后调试无法正常工作

我在调试我的 preact 项目时遇到了一些问题,大多数 js 错误都没有出现在控制台中。


例如,我将这段代码添加到我的组件中:


<button onClick={() => {

  const someVar = someUnknownVariable;

}}>

  fire error

</button>

当我点击按钮时,没有出现错误,说 someUnknownVariable is not defined,其他 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 版本后发生的,请提供任何帮助。


倚天杖
浏览 153回答 1
1回答

梦里花落0921

问题出在旧的 eventListener 上,错误window.addEventListener('error', function(event) {});导致预调试问题,当我删除它时,问题就解决了
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript