javascript - 来自 3rd 方库的 Next/image 组件引发 next.config.js 错误
问题描述
我们开发了一个库来将我们的无头 CMS 与 Next.js 配对。这个库还包含一个next/image
组件来额外处理我们的 cms 的有效负载。
type SomeImageProps = Omit<ImageProps, ExcludedTypes> & {
imageFile: ImageFile;
className?: string;
};
export const SomeNextImage: React.FC<SomeImageProps> = ({
imageFile,
className,
...nextImageProps
}) => {
...
return isBitmapImage(imageFile) ? (
<Image
className={className}
src={imageFile.imageUrl}
width={imageFile.width}
height={imageFile.height}
{...nextImageProps}
/>
) : (
...
);
};
问题是,尝试通过从 导入该组件来使用该组件,node_modules
将引发以下错误:
错误:Invalid src prop (...) on
next/image
,主机名“...”未在您的图像下配置next.config.js
如果您没有将主机名添加到配置中,则该错误是有意义的,但我们有。将组件本身复制到项目中解决了这个问题,因此我们猜测:我们的库无法访问next.config.js
或不知道它的位置。
有没有办法将项目的 next.config.js 用作第 3 方库?如果没有,您将如何解决这个问题?
解决方案
推荐阅读
- javascript - 如何修复由 react-redux 中的循环依赖引起的“不变违规”
- javascript - 如何在nodejs中发布请求后在html上显示响应消息
- javascript - 为什么 video.width 是 0 但实际上是 539?
- python - 很想在 Maya 中创建一个循环遍历场景中所有透视摄像机的 Python 脚本?
- action - 如何在 Photoshop CC 中将“导出为”记录为动作
- visual-studio - 如何修复:(不能有隐式远跳转或调用近标签)和(使用假定为错误的寄存器)
- java - 从命令行运行程序时找不到类
- nltk - 为什么 gensim 在预处理过程中会忽略下划线?
- excel - VBA 行为怪异,无法获取存储在变量中的值
- python - 如何在Python中按组更改值的计数器