简体   繁体   English

Next Export 脚本不适用于 next/image 组件

[英]Next Export script is not working with next/image component

I have a project.我有一个项目。 I want to build and export it but there is an error.我想构建并导出它,但出现错误。

Here is my build script in package.json file.这是我在package.json文件中的构建脚本。

"scripts": {
    "build": "next build && next export"
}

Here is my component where I'm using next/image这是我使用next/image

import Image from 'next/image'

export default function Logo(){
    return(
        <Image 
            src={process.env.website_url ? (process.env.website_url + "/img/logo/logo1.png") : "/img/logo/logo1.png" } 
            width={width} 
            height={height}
            alt="logo"
        />
    )
}

And here is the error when I want to build the project:这是我想构建项目时的错误:

Error: Image Optimization using Next.js' default loader is not compatible with `next export`.

So, what sould I do now.那么,我现在该怎么办。 Should I use a different loader or what?我应该使用不同的装载机还是什么? Thanks.谢谢。

next export is only for static pages. next export仅适用于静态页面。 So next/image are images optimized and loaded with server started by next start (They are images on demand not on build).所以 next/image 是优化的图像,并在下一次启动时加载服务器(它们是按需而不是构建的图像)。 next start starts server which has Image optimization API. next start启动具有图像优化 API 的服务器。 That's why its unable to export.这就是它无法导出的原因。 Try using other image loading service.尝试使用其他图像加载服务。 You can also try only building the next js (next build) without next export and use next start to start server which will handle the Image optimization.您也可以尝试只构建下一个 js(下一个构建)而不进行下一次导出,并使用 next start 来启动将处理图像优化的服务器。

You can Also configure your own loader for Image optimization.您还可以为图像优化配置自己的加载程序。 Refer these :参考这些:

Loader reference 装载机参考

next-optimized-images下一个优化图像

Next JS Doc message下一个 JS Doc 消息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM