[英]ES6 (babel+webpack) Silent errors in the class methods
问题 :
我使用一个webpack捆绑包来定位和运输ES6。
我想在没有try / catch块的情况下捕获错误。 我如何获得此消息,原因是什么让异常保持沉默? 这个问题不仅在constructor()方法中存在。 类的任何方法都会像这样默默地发出错误
import React from 'react';
class TestComponent extends React.Component {
constructor(props) {
super(props);
/*
Try/catch block works fine.
"test is not defined(…)"
*/
try {
test.fake(1);
} catch (e) {
console.error(e);
}
// Line below should theoretically throw exception but it does not
test.fake(1);
}
render() {
return <div>TEST</div>
}
}
export default TestComponent;
这是我的webpack.config
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
devtool: 'cheap-module-eval-source-map',
//devtool: 'eval',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./src/js/main'
],
output: {
filename: 'app.js',
path: path.join(__dirname, 'dist'),
publicPath: '/assets/'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new ExtractTextPlugin('app.css', {
allChunks: true
}),
new webpack.DefinePlugin({
__DEV_TOOLS__: true
}),
new HtmlWebpackPlugin({
title: 'Redux Boilerplate',
filename: 'index.html',
template: 'index.template.html'
})
],
resolve: {
root: path.resolve('./src/js')
},
module: {
loaders: [
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!sass')
}, {
test: /\.js$/,
loaders: ['babel'],
exclude: /node_modules/
}
]
},
cssnext: {
browsers: 'last 2 versions'
}
};
Webpack会编译而不编译您的代码。 当您对上述内容进行反编译时,没有语法问题或缺少要求,因此webpack只需通过babel运行该代码并将其编译到EC5。 您可能想要寻找在编译后实际执行代码的加载程序或插件。 更好的是,将webpack与gulp或karma结合使用,以获得完整的解决方案。 我们使用这样的东西。 https://github.com/webpack/karma-webpack
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.