【发布时间】:2021-11-08 02:47:13
【问题描述】:
我正在尝试静态导入图像以用于下一个/图像,但我不断收到错误:
./public/IMG_2117.png
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
next.config.js 文件没有自定义加载程序或任何东西 - documentation 表示它应该默认/自动与 next dev 一起工作(即不需要自定义加载程序):
module.exports = {
images: {
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
}
}
我正在像这样导入图像文件
import Image from "next/image"
import image1 from "../public/IMG_2117.png"
为什么会出现此错误,我该如何解决?
【问题讨论】:
-
您使用的是哪个 Next.js 版本?仅 v11 及更高版本支持静态图像导入。
-
这能回答你的问题吗? I can't reference an image in Next.js
-
@brc-dd 谢谢,我使用的是 nextjs v10。既然你的评论解决了这个问题,它应该真的成为一个答案:)