reactjs - Webpack5 - 模块解析失败:意外字符 '�' (1:0) 您可能需要合适的加载器
问题描述
尝试将本地图像导入我的 React 项目。我正在使用这样的陈述,没什么特别的。
<Image source={require('./redvelvet.png')}></Image>
这是它产生的错误。
ERROR in ./src/components/redvelvet.png 1:0
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
@ ./src/components/MachineTemplate.js 157:16-42
@ ./src/components/App.js 6:0-48 21:28-43
@ ./src/index.js 1:0-35
我很确定我已将其范围缩小到我的 webpack.config 文件,但对于我的生活,我无法弄清楚我做错了什么。
const path = require("path");
const webpack = require("webpack");
module.exports = {
entry: "./src/index.js",
output: {
path: path.resolve(__dirname, "./static/frontend"),
filename: "[name].js",
},
module: {
rules: [
{
test: /\.js$|jsx/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
},
],
},
optimization: {
minimize: true,
},
plugins: [
new webpack.DefinePlugin({
"process.env": {
// This has effect on the react lib size
NODE_ENV: JSON.stringify("production"),
},
}),
],
};
任何帮助表示赞赏。感觉就像我在这里想念的一样简单。
解决方案
推荐阅读
- r - 如何使用 dplyr::summarise “带来另一个变量”
- javascript - botConnection.activity$ node.js BOT
- r - 运行 lmer 时 R 挂起
- regex - 从 Twitter 数据集中删除或替换 URL 和 RT
- python - 通过 pyodbc (Python 3.x) 执行 SQL 脚本时,“CREATE PROCEDURE #X”失败
- ruby-on-rails - 如何将供应商资产导入 webpacker?
- highcharts - 如何在 Highcharts 中使用外部按钮导出 CSV 和 XLS
- c# - Xamarin 表单更新 UI
- autoconf - 使用 autoconf 为汇编语言程序创建构建脚本
- javascript - 在 d3 地理图上的固定位置附加链接图形