reactjs - 为什么 React 将其错误引用到我的包而不是源映射(Webpack 5.44.8)?
问题描述
我是“警告:列表中的每个孩子都应该有一个唯一的“关键”道具。” 错误,所以我决定在我的 Webpack 配置中实现源映射。这似乎有效。我可以在浏览器 (FireFox) 中查看我的源地图,并且我有一个 main.map.js 文件作为名为“main.js”的包的子文件。此外,我通过故意打错字来测试源地图,并且错误引用了我的源地图。
但是,React 错误返回我的包中的位置而不是源映射。
Check the render method of `Table`. See https://reactjs.org/link/warning-keys for more information.
at http://localhost:3000/main.js:34174:66
at Table (http://localhost:3000/main.js:118750:18)
at ReactTable (http://localhost:3000/main.js:118684:13)
这是我的 webpack.config.js 内容:
const path = require('path');
const webpackResolveConfig = require(path.resolve(__dirname, 'webpack.config.resolve.js'));
const HtmlWebpackPlugin = require('html-webpack-plugin');
const autoprefixer = require('autoprefixer');
const isDevelopment = process.env.NODE_ENV !== 'production';
module.exports = {
mode: 'development',
target: isDevelopment ? 'web' : 'browserslist',
entry: './src/index.tsx',
output: {
path: path.resolve(__dirname, 'dist'),
clean: true,
},
devServer: {
contentBase: path.resolve(__dirname, 'dist'),
watchContentBase: true,
filename: 'bundle.js',
compress: true,
hot: true,
host: 'localhost',
port: 3000,
historyApiFallback: true,
clientLogLevel: 'debug',
},
devtool: isDevelopment ? 'source-map' : 'eval-cheap-source-map',
module: {
rules: [
{
test: /\.js$/,
enforce: "pre",
use: ["source-map-loader"],
},
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules|\.d\.ts$/
},
{
test: /\.d\.ts$/,
loader: 'ignore-loader'
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
{
test: /\.css$/i,
use: [
"style-loader",
// Translates CSS into CommonJS
"css-loader",
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
autoprefixer()
]
}
}
},
],
},
{
test: /\.s[ac]ss$/i,
use: [
"style-loader",
// Translates CSS into CommonJS
"css-loader",
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
autoprefixer()
]
}
}
},
// Compiles Sass to CSS
{
loader: "sass-loader",
options: {
// Prefer dart-sass
implementation: require("sass"),
// See https://github.com/webpack-contrib/sass-loader/issues/804
webpackImporter: false,
sassOptions: {
fiber: require("fibers"),
includePaths: ['./node_modules']
}
}
}
],
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
inject: 'body',
}),
],
...webpackResolveConfig,
};
如果您想知道,这是我的 webpack.config.resolve.js 内容:
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
/**
* Determine the array of extensions that should be used to resolve modules.
*/
module.exports = {
resolve: {
modules: ['node_modules'],
plugins: [new TsconfigPathsPlugin({})],
extensions: [
'.js', '.jsx',
'.ts', '.tsx',
'.scss', '.css',
'.json',
]
},
};
解决方案
推荐阅读
- node.js - 数据响应无法在反应路由器中映射
- jquery - 如何找到包含一些完全匹配的单词的div
- react-native - 如何在反应原生 IOS 中接收 firebase 推送通知?
- android - 无法在 Onclick 事件上的动态添加的编辑文本 android 中设置编辑文本值
- plsql - Oracle 数据库中可以创建多少个视图?
- java - Rest Api - 给定以下输出,正确的 url 格式是什么?
- windows - Maven 3.3.9版本升级windows重启后恢复到以前的版本
- apache-spark - Apache Spark 和 Livy 集群
- python - 我在 pycharm 上遇到 tensorflow 安装错误
- javascript - 比较javascript中的树数据