小编Lee*_*Lee的帖子

将 next/image 与 TypeScript 一起使用时,获取主机未配置错误

我知道在不使用 TypeScript 的情况下使用 Next.js 图像组件时,需要在 中配置 URL next.config.js,但我不确定为什么这不适用于 TypeScript。

....,未在您的图像下配置next.config.js查看更多信息:https ://nextjs.org/docs/messages/next-image-unconfigured-host

解决方法是什么?或者是我使用常规img标签的唯一选择?

图像组件:

<Image
    src="https://images.unsplash.com/photo-1621794279356-0150106a4b45?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1"
    alt="blog title"
    width="100"
    height="100"
/> 
Run Code Online (Sandbox Code Playgroud)

next.config.ts

export const images = {
  domains: [
    "images.unsplash.com"
  ],
};
Run Code Online (Sandbox Code Playgroud)

typescript next.js

7
推荐指数
2
解决办法
7370
查看次数

标签 统计

next.js ×1

typescript ×1