如果使用create-react-app和require导入图像,require返回一个ES模块而不是字符串。这是因为在file-loader中,esModule选项是默认启用的。

用以下方式之一导入图像:

const image = require('../path/to/image.jpg').default;
// OR
import image from '../path/to/image.jpg';

相关文章:

  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
  • 2021-10-25
  • 2021-12-26
  • 2021-12-24
  • 2022-12-23
相关资源
相似解决方案