我正在尝试部署一个简单的 Next.JS 应用程序,该应用程序只有一个前端,没有后端或与 AWS Amplify 的数据库连接,但我在构建时不断收到此错误:
2023-05-20T17:00:51.907Z [INFO]: # Checking for Git submodules at: /codebuild/output/src963349001/src/static/.gitmodules
2023-05-20T17:00:51.911Z [ERROR]: !!! CustomerError: Cannot read 'next' version in package.json.
我不明白为什么它无法读取下一个版本。它就在 package.json 中:
{
"name": "one-two-static",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build && next export",
"start": "next start"
},
"dependencies": {
"@types/node": "20.2.1",
"@types/react": "18.2.6",
"@types/react-dom": "18.2.4",
"autoprefixer": "10.4.14",
"eslint": "8.41.0",
"eslint-config-next": "13.4.3",
"next": "13.4.3",
"postcss": "8.4.23",
"react": "18.2.0",
"react-dom": "18.2.0",
"tailwindcss": "3.3.2",
"typescript": "5.0.4"
}
}
这是我的 next.config.js:
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
output: 'standalone',
experimental: {
outputStandalone: true,
}
}
module.exports = nextConfig
我遇到了类似的问题,只需要运行
npm install
,然后将 package.json 和 package.lock 推送到部署到 amplify 的存储库。
似乎在包构建中包含
next export
可能会导致警告错误,您可以尝试删除它并将其添加到 next.config.js
有类似的问题,我通过更改 package.json 修复了它
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
出于某种原因,我将 next 作为开发依赖项,一旦我将其移至依赖项,它就为我修复了它。