为外部域的图像配置下一个JS
我对next.config.js有问题。我目前正在运行一个带有打字稿的Next JS的项目。在这个项目中,我正在与TrixJS合作, @react-three/fiber& @react-three/drei。但是我也想包括一些特定公共YouTube URL的图像。 在较旧的项目中,我已经实施了这样的内部三个J的实现:
module.exports = {
reactStrictMode: true,
images: {
domains: ['i3.ytimg.com', 'img.youtube.com'],
formats: ['image/webp'],
},
}
在我的next.config.js上,它仍然像魅力一样起作用。但是,当我将其放入当前项目并尝试加载图像时,我会发现错误说:
错误:
next/image
上的无效src prop([url]),hostName“ img.youtube.com”未在next.config.js
当前的 图像中配置Next.config.js文件
module.exports = {
reactStrictMode: true,
images: {
domains: ['i3.ytimg.com', 'img.youtube.com'],
formats: ['image/webp'],
},
}
const withTM = require('next-transpile-modules')(['three', '@react-three/fiber', '@react-three/drei']);
module.exports = withTM();
现在在我的组件上:
export default function ProjectCard({ song }: { song: Lyrics }) {
const img = hqDefault(song.thumbnailURL);
return (
<div>
{song.singer}
<Image src={img} alt={`${song.singer} ${song.title}`} layout="fill" />
</div>
)
}
HQDEFAULT函数:
export const hqDefault = (url: string): string => {
return `https://img.youtube.com/vi/${url}/hqdefault.jpg`;
}
任何帮助都将被应用!
I'm having an issue with next.config.js. I'm currently running a project with next js on typescript. In this project i am working with ThreeJs, @react-three/fiber & @react-three/drei. But I also want to include some images from a specific public YouTube url.
In older projects i have implemented this withought having ThreeJs inside like this:
module.exports = {
reactStrictMode: true,
images: {
domains: ['i3.ytimg.com', 'img.youtube.com'],
formats: ['image/webp'],
},
}
That being on my next.config.js and it still works like a charm. But when I put it in my current project and try to load an image I get error saying:
Error: Invalid src prop ([url]) on
next/image
, hostname "img.youtube.com" is not configured under images in yournext.config.js
Current next.config.js file
module.exports = {
reactStrictMode: true,
images: {
domains: ['i3.ytimg.com', 'img.youtube.com'],
formats: ['image/webp'],
},
}
const withTM = require('next-transpile-modules')(['three', '@react-three/fiber', '@react-three/drei']);
module.exports = withTM();
On my component now:
export default function ProjectCard({ song }: { song: Lyrics }) {
const img = hqDefault(song.thumbnailURL);
return (
<div>
{song.singer}
<Image src={img} alt={`${song.singer} ${song.title}`} layout="fill" />
</div>
)
}
hqDefault Function:
export const hqDefault = (url: string): string => {
return `https://img.youtube.com/vi/${url}/hqdefault.jpg`;
}
Any help will be appriciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该导出单个配置对象。
首先,安装“下一代组合 - plugins”:
导入它:
然后像这样导出配置:
You are supposed to export a single configuration object.
First, Install 'next-compose-plugins':
Import it:
And then export your config like this: