[英]Next deployment fails only on Amplify
我正在尝试在 AWS Amplify 上部署 Next.js 应用程序,但它一直失败。
Build 在本地环境中运行良好,我什至成功部署在 Vercel 上。
但它只在 Amplify 上失败:(
我能够通过创建一个.babelrc
文件进行部署,但我正在寻找一个更好的解决方案来保留 SWC。
我试过了:
rm package-lock.json && rm -rf node_modules
并重新安装( npm install --force
)@next/swc-linux-x64-gnu
和@next/swc-linux-x64-musl
作为 optionalDependenciesnext.config.js
swcMinify
选项设置为false
next.config.js
中的compiler
选项▼ 环境
v16.13.2 x64 linux
▼ package.json
{
"name": "my-project",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@svgr/webpack": "^6.2.1",
"clsx": "^1.2.1",
"framer-motion": "^6.4.3",
"next": "12.2.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-query": "^3.39.1",
"react-use": "^17.4.0",
"recoil": "^0.7.4",
"styled-components": "^5.3.5",
"twemoji": "^14.0.2"
},
"devDependencies": {
"@types/node": "18.0.3",
"@types/react": "18.0.15",
"@types/react-dom": "18.0.6",
"@types/styled-components": "^5.1.25",
"eslint": "8.19.0",
"eslint-config-next": "12.2.2",
"typescript": "4.7.4"
}
}
▼ next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack(config) {
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
})
return config
},
reactStrictMode: true,
swcMinify: true,
compiler: {
styledComponents: {
displayName: true,
ssr: true,
},
},
}
module.exports = nextConfig
▼ 错误日志
# Starting phase: preBuild
# Executing command: nvm use --lts
2022-07-13T23:48:13.094Z [INFO]: Now using node v16.13.2 (npm v8.1.2)
2022-07-13T23:48:13.095Z [INFO]: # Executing command: node -e 'console.log(process.version, process.arch, process.platform)'
2022-07-13T23:48:13.122Z [INFO]: v16.13.2 x64 linux
2022-07-13T23:48:13.125Z [INFO]: # Executing command: npm ci --include=optional
2022-07-13T23:48:20.109Z [WARNING]: npm
2022-07-13T23:48:20.111Z [WARNING]: WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
2022-07-13T23:48:27.374Z [INFO]: added 508 packages, and audited 509 packages in 14s
2022-07-13T23:48:27.377Z [INFO]: 100 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
2022-07-13T23:48:27.389Z [INFO]: # Completed phase: preBuild
2022-07-13T23:48:27.389Z [INFO]: # Starting phase: build
# Executing command: npm run build
2022-07-13T23:48:27.663Z [INFO]: > my-project@0.1.0 build
> next build
2022-07-13T23:48:28.057Z [INFO]: info - SWC minify release candidate enabled. https://nextjs.link/swcmin
2022-07-13T23:48:28.065Z [INFO]: warn - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
2022-07-13T23:48:28.086Z [INFO]: Attention: Next.js now collects completely anonymous telemetry regarding usage.
2022-07-13T23:48:28.086Z [INFO]: This information is used to shape Next.js' roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
https://nextjs.org/telemetry
2022-07-13T23:48:28.174Z [INFO]: info - Linting and checking validity of types...
2022-07-13T23:48:33.726Z [INFO]: info - Creating an optimized production build...
2022-07-13T23:48:34.350Z [INFO]: info - Downloading WASM swc package...
2022-07-13T23:48:35.445Z [INFO]: info - Using experimental wasm build of next-swc
2022-07-13T23:48:35.613Z [WARNING]: warn - Attempted to load @next/swc-linux-x64-gnu, but an error occurred: libssl.so.1.1: cannot open shared object file: No such file or directory
2022-07-13T23:48:35.614Z [WARNING]: warn - Attempted to load @next/swc-linux-x64-gnux32, but it was not installed
warn - Attempted to load @next/swc-linux-x64-musl, but an error occurred: libc.musl-x86_64.so.1: cannot open shared object file: No such file or directory
2022-07-13T23:48:48.873Z [WARNING]: panicked at 'The global thread pool has not been initialized.: ThreadPoolBuildError { kind: IOError(Error { kind: Unsupported, message: "operation not supported on this platform" }) }', /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:170:10
Stack:
Error
at module.exports.__wbg_new_693216e109162396 (/codebuild/output/src358588912/src/my-project/node_modules/next/wasm/@next/swc-wasm-nodejs/wasm.js:202:17)
at wasm://wasm/059aa236:wasm-function[5445]:0xf90917
at wasm://wasm/059aa236:wasm-function[13700]:0x11eca7b
at wasm://wasm/059aa236:wasm-function[9995]:0x1186adc
at wasm://wasm/059aa236:wasm-function[11009]:0x11b6862
at wasm://wasm/059aa236:wasm-function[12785]:0x11e5cdd
at wasm://wasm/059aa236:wasm-function[11383]:0x11c358f
at wasm://wasm/059aa236:wasm-function[10017]:0x1187e72
at wasm://wasm/059aa236:wasm-function[1151]:0x98decd
at wasm://wasm/059aa236:wasm-function[654]:0x75f3f2
2022-07-13T23:48:48.911Z [WARNING]: panicked at 'The global thread pool has not been initialized.: ThreadPoolBuildError { kind: GlobalPoolAlreadyInitialized }', /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:170:10
Stack:
Error
at module.exports.__wbg_new_693216e109162396 (/codebuild/output/src358588912/src/my-project/node_modules/next/wasm/@next/swc-wasm-nodejs/wasm.js:202:17)
at wasm://wasm/059aa236:wasm-function[5445]:0xf90917
at wasm://wasm/059aa236:wasm-function[13700]:0x11eca7b
at wasm://wasm/059aa236:wasm-function[9995]:0x1186adc
at wasm://wasm/059aa236:wasm-function[11009]:0x11b6862
at wasm://wasm/059aa236:wasm-function[12785]:0x11e5cdd
at wasm://wasm/059aa236:wasm-function[11383]:0x11c358f
at wasm://wasm/059aa236:wasm-function[10017]:0x1187e72
at wasm://wasm/059aa236:wasm-function[1151]:0x98decd
at wasm://wasm/059aa236:wasm-function[654]:0x75f3f2
2022-07-13T23:48:49.415Z [WARNING]: Failed to compile.
static/chunks/pages/_app-8aa2b8cf1034125e.js from Terser
unreachable
RuntimeError: unreachable
at wasm://wasm/059aa236:wasm-function[9995]:0x1186aff
at wasm://wasm/059aa236:wasm-function[11009]:0x11b6862
at wasm://wasm/059aa236:wasm-function[12785]:0x11e5cdd
at wasm://wasm/059aa236:wasm-function[11383]:0x11c358f
at wasm://wasm/059aa236:wasm-function[10017]:0x1187e72
at wasm://wasm/059aa236:wasm-function[1151]:0x98decd
at wasm://wasm/059aa236:wasm-function[654]:0x75f3f2
at wasm://wasm/059aa236:wasm-function[654]:0x760098
at wasm://wasm/059aa236:wasm-function[3154]:0xd6fe73
at wasm://wasm/059aa236:wasm-function[654]:0x75f24f
static/chunks/framework-a1d4bfd54c97f1bc.js from Terser
unreachable
RuntimeError: unreachable
at wasm://wasm/059aa236:wasm-function[9995]:0x1186afd
at wasm://wasm/059aa236:wasm-function[11009]:0x11b6862
at wasm://wasm/059aa236:wasm-function[12785]:0x11e5cdd
at wasm://wasm/059aa236:wasm-function[11383]:0x11c358f
at wasm://wasm/059aa236:wasm-function[10017]:0x1187e72
at wasm://wasm/059aa236:wasm-function[1151]:0x98decd
at wasm://wasm/059aa236:wasm-function[654]:0x75f3f2
at wasm://wasm/059aa236:wasm-function[654]:0x760098
at wasm://wasm/059aa236:wasm-function[3154]:0xd6fe73
at wasm://wasm/059aa236:wasm-function[654]:0x75f24f
2022-07-13T23:48:49.417Z [WARNING]:
2022-07-13T23:48:49.417Z [WARNING]: > Build failed because of webpack errors
2022-07-13T23:48:49.456Z [ERROR]: !!! Build failed
2022-07-13T23:48:49.457Z [ERROR]: !!! Non-Zero Exit Code detected
2022-07-13T23:48:49.457Z [INFO]: # Starting environment caching...
2022-07-13T23:48:49.457Z [INFO]: # Uploading environment cache artifact...
2022-07-13T23:48:49.532Z [INFO]: # Environment caching completed
Terminating logging...
将 nextjs 版本降级到 12.2.0,应该可以正常工作!! 详细信息: https ://github.com/vercel/next.js/issues/38436
我认为这是因为 SwcMinify 或 TypeScript 插件。
我遇到了同样的问题,我禁用了 SwcMinify 并在.eslintrc.json
中编辑了 TypeScript 插件。
"plugins": ["@typescript-eslint/eslint-plugin"],
"extends": [
"eslint:recommended",
"next/core-web-vitals",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
我有同样的问题,要解决它,我必须完全删除node_modules文件夹并使用yarn install重新安装所有包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.