我有一个项目。我想构建并导出它,但出现错误。
这是我的构建脚本package.json
file.
"scripts": {
"build": "next build && next export"
}
这是我正在使用的组件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"
/>
)
}
当我想构建项目时,这是错误:
Error: Image Optimization using Next.js' default loader is not compatible with `next export`.
那么,我现在该怎么办呢。我应该使用不同的加载程序还是什么?谢谢。
编辑:我创建了一个 server.js 文件并修改了 package.json 脚本。
服务器.js 文件:
const express = require('express')
const server = express()
const next = require('next')
const dev = process.env.NODE_ENV !== 'production'
const app = next({dev})
const handle = app.getRequestHandler()
const port = 3000
app.prepare().then(()=>{
server.get('*', (req, res)=>{
return handle(req,res)
})
server.listen(port, (err) => {
if(err) console.log(err)
console.log(`SERVER SUCCESS: ${port}`)
})
}).catch((e)=>{
console.log(e.stack)
process.exit(1)
})
package.json 文件中的脚本:
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "node server.js"
}
服务器在本地主机上工作,但在主机上不工作。出现 503 服务不可用错误。