reactjs - React CSS 不能使用公共图片
问题描述
我创建了一个项目create-react-app project_name
,然后我尝试使用公共文件夹中的图像作为背景,并在 css 中使用此代码
background-image: url('/images/ernestDrum.jpeg');
然后我
./src/App.css (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-4-1!./node_modules/postcss-loader/src??postcss!./src/App.css) Error: Can't resolve '/images/ernestDrum.jpeg' in 'E:\project\ernest\src'
在以前的项目中遇到了这个错误,我使用相同的代码并且它有效
解决方案
将 react-scipts 从 3.xx 更新到 4.xx 后我遇到了同样的错误
并发现了这个问题https://github.com/facebook/create-react-app/issues/9870
回滚到 3.xx 可以解决这个问题
推荐阅读
- c# - 需要将科学价值转化为文字
- python - 如何检测 Wav 音频中是否存在一个或多个“空白区域”?
- flutter - 在 Dart 中将 ECPrivateKey/ECPublicKey 转换为 PEM 字符串
- wpf - 什么样的事情可能会导致 OutOfMemoryException?
- javascript - 从外部 html 文件和 css 生成 pdf
- sqlite - 在电话上使用带有 GUID 数据的字符串或使用具有 20,000 行的 SQLite 表的 int 之间的性能损失?
- angularjs - 使用 AngularJS 显示 Bootstrap 3 模态
- bash - 是否可以在 irc 中运行 bash 命令?
- webpack - TerserPlugin Webpack 排除/测试未按预期工作
- python - 在python中切片体积