我试图找出如何减小 SSR 应用程序(Next.js & Serverless Framework)的软件包大小,以使其保持在 AWS 限制的 250MB 以下:
An error occurred: ServerLambdaFunction - Unzipped size must be smaller than 262144000 bytes (Service: AWSLambdaInternal; Status Code: 400;
该应用程序是通过运行next build && sls deploy
部署的。
未打包的归档文件大小超过 600MB,是 AWS 允许 Lambda 的 250MB 的两倍以上。下面是 node_modules 中最大依赖项的列表。我可以看到,将其中一些移动到开发依赖项中可以稍微减少它,但这并不能解决问题。
如果有人能指点我正确的方向,我将不胜感激。
这是我的 package.json:
{
"name": "ssr-ui",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "next build",
"deploy": "next build && sls deploy",
"start": "next start",
"dev": "next dev"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@aws-amplify/api": "^3.2.4",
"@aws-amplify/auth": "^3.4.4",
"@aws-amplify/core": "^3.5.4",
"@aws-amplify/storage": "^3.3.4",
"@aws-amplify/ui-react": "^0.2.21",
"antd": "^4.6.4",
"antd-img-crop": "^3.10.0",
"axios": "^0.20.0",
"country-state-picker": "^1.1.1",
"echarts": "^4.9.0",
"echarts-for-react": "^2.0.16",
"express": "^4.17.1",
"next": "^9.5.3",
"next-react-svg": "^1.1.2",
"path-match": "^1.2.4",
"query-string": "^6.13.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.2.0",
"react-share": "^4.2.1",
"sass": "^1.26.11",
"serverless-apigw-binary": "^0.4.4",
"serverless-domain-manager": "^4.2.0",
"serverless-http": "^2.5.0",
"url": "^0.11.0"
},
"devDependencies": {
"@types/jest": "^26.0.14",
"@types/node": "^14.10.3",
"@types/react": "^16.9.49",
"@types/react-dom": "^16.9.8",
"@types/react-router-dom": "^5.1.5",
"typescript": "^4.0.2"
}
}
我的serverless.yml文件如下:
service: ssr-react-next
provider:
name: aws
runtime: nodejs12.x
region: ap-southeast-2
stage: ${self:custom.secrets.NODE_ENV}
environment:
NODE_ENV: ${self:custom.secrets.NODE_ENV}
functions:
server:
handler: index.server
events:
- http: ANY /
- http: ANY /{proxy+}
plugins:
- serverless-apigw-binary
- serverless-domain-manager
custom:
secrets: ${file(secrets.json)}
apigwBinary:
types:
- '*/*'
customDomain:
domainName: ${self:custom.secrets.DOMAIN}
basePath: ''
stage: ${self:custom.secrets.NODE_ENV}
createRoute53Record: true
谢谢!
useServerlessTraceTarget: true
来解决你的问题。 - undefined