zhangyuang / ssr

A most advanced ssr framework support React17/React18/Vue2/Vue3 on Earth that implemented serverless-side render specification.
http://doc.ssr-fc.com/
MIT License
2.61k stars 284 forks source link

serverless dev无法deploy #259

Closed hechuan9 closed 1 year ago

hechuan9 commented 1 year ago

提问前请确认以下几点信息,否则你的问题将不会被解答

详细描述你的问题

  1. 模版直接创建my-ssr-package,
  2. 一些必要修改,见下文
  3. 部署到ali fc
  4. deploy失败
    Deploy error: PUT /services/serverless-ssr/functions/ssr failed with 400. requestid: 935f34e6-3c31-4d70-891d-3b288469c69a, message: Bad data in request body.

期望的结果

  1. 能解决部署的问题(至少有个hack)
  2. 能解决大包部署,比如说pdf-js的问题(follow up)
  3. 阿里云的serverless dev会不会允许一些更方便的部署方法?比如使用阿里应用,让阿里的服务器来complie?

当前使用的版本

├─ ssr-common-utils@6.2.61
├─ ssr-core-react@6.2.16
├─ ssr-hoc-react@6.2.10
├─ ssr-mini-css-extract-plugin@1.6.3
├─ ssr-plugin-midway@6.2.18
├─ ssr-plugin-react@6.2.56
├─ ssr-serialize-javascript@6.0.4
├─ ssr-types@6.2.36
├─ ssr-vite-plugin-style-import@2.0.1
├─ ssr-webpack@6.2.11
├─ ssr-window@3.0.0
├─ ssr@6.2.44
├─ ssri@7.1.1
└─ webpack@4.46.0
   └─ ssri@6.0.2

复现仓库地址

https://github.com/hechuan9/my-ssr-project

你本人对问题可能的原因判断(如果你能大概判断的话)

  1. 一开始看到的错误是 如果直接用模版产生的代码跑npm run deploy会看到
    TypeError: The "id" argument must be of type string. Received undefined
    at new NodeError (node:internal/errors:393:5)
    at validateString (node:internal/validators:161:11)
    at Module.require (node:internal/modules/cjs/loader:1044:3)
    at require (node:internal/modules/cjs/helpers:103:18)
    at compileTypeScript (/Users/hechuan/bankcorpconnect/my-ssr-project/node_modules/@midwayjs/fcli-plugin-package/node_modules/@midwayjs/command-core/dist/utils/compileTypeScript.js:13:16)
    at PackagePlugin.compile (/Users/hechuan/bankcorpconnect/my-ssr-project/node_modules/@midwayjs/fcli-plugin-package/dist/index.js:453:88)
    at CommandCore.execLifecycle (/Users/hechuan/bankcorpconnect/my-ssr-project/node_modules/@midwayjs/command-core/dist/core.js:178:21)
    at CommandCore.invoke (/Users/hechuan/bankcorpconnect/my-ssr-project/node_modules/@midwayjs/command-core/dist/core.js:145:9)
    at AliyunFCPlugin.deployUseServerlessDev (/Users/hechuan/bankcorpconnect/my-ssr-project/node_modules/@midwayjs/fcli-plugin-fc/dist/index.js:181:9)
    at CommandCore.execLifecycle (/Users/hechuan/bankcorpconnect/my-ssr-project/node_modules/@midwayjs/command-core/dist/core.js:178:21) {
    code: 'ERR_INVALID_ARG_TYPE'
    }

    经过分析,我认为是因为,@midway插件和ssr 6.0.0版本不匹配。 首先修改devdependency

    "ssr": "^6.2.44",
    "ssr-plugin-midway": "^6.2.18",
    "ssr-plugin-react": "^6.2.56",
    "@midwayjs/cli-plugin-faas": "^2.0.10",
    "@midwayjs/fcli-plugin-fc": "^2.0.10",
    "@midwayjs/fcli-plugin-package": "^2.0.10",
  2. 部署系统换成了serverless dev,但是错误了。做了一个极简的包,如仓库所示。 Zip已经是最小尺寸:
    Package artifact...
    - Artifact file code.zip
    - Biggest Dependencies list:
    6.7M    swiper
    5.1M    moment
    5.9M    lodash
    5.0M    pm2
    2.9M    react-dom
    - Zip size 14.69MB

    得到如下错误

    Deploy error: PUT /services/serverless-ssr/functions/ssr failed with 400. requestid: 935f34e6-3c31-4d70-891d-3b288469c69a, message: Bad data in request body.

Follow up

因为极简包都跑不通,所以没法测试pdf-js的影响,但是我有个很大的包pdf-js,前面那个issue的,不能通过whitelist+dev dependency解决,如果能解决部署的问题,不知道能不能顺便也解决这个问题。

Package artifact...
 - Artifact file code.zip
 - Biggest Dependencies list:
     34M    pdfjs-dist
    7.3M    web-streams-polyfill
    7.7M    swiper
    6.4M    webpack
    5.1M    moment
 - Zip size 62.84MB

但是大包会有超时问题

✖ Creating Service, Function (602.49s)
[urllib:warn] [Tue Jan 24 2023 22:07:55 GMT-0500 (Eastern Standard Time)] [1] [worker:8586] PUT http://fc-hz-yunqi-temp-code.oss-cn-hangzhou.aliyuncs.com/1229686316936963/bank-corp-website/undefined-f0b702a5-85ce-4174-8c48-8cb862e79674 callback twice!!!
[urllib:warn] [Tue Jan 24 2023 22:07:55 GMT-0500 (Eastern Standard Time)] [1] [worker:8586] ResponseTimeoutError: Response timeout for 600000ms, PUT http://fc-hz-yunqi-temp-code.oss-cn-hangzhou.aliyuncs.com/1229686316936963/bank-corp-website/undefined-f0b702a5-85ce-4174-8c48-8cb862e79674 -1 (connected: true, keepalive socket: false, agent status: {"createSocketCount":1,"createSocketErrorCount":0,"closeSocketCount":0,"errorSocketCount":0,"timeoutSocketCount":0,"requestCount":0,"freeSockets":{},"sockets":{"fc-hz-yunqi-temp-code.oss-cn-hangzhou.aliyuncs.com:80:":1},"requests":{}}, socketHandledRequests: 1, socketHandledResponses: 0)
headers: {}
stack: ResponseTimeoutError: Response timeout for 600000ms, PUT http://fc-hz-yunqi-temp-code.oss-cn-hangzhou.aliyuncs.com/1229686316936963/bank-corp-website/undefined-f0b702a5-85ce-4174-8c48-8cb862e79674 -1 (connected: true, keepalive socket: false, agent status: {"createSocketCount":1,"createSocketErrorCount":0,"closeSocketCount":0,"errorSocketCount":0,"timeoutSocketCount":0,"requestCount":0,"freeSockets":{},"sockets":{"fc-hz-yunqi-temp-code.oss-cn-hangzhou.aliyuncs.com:80:":1},"requests":{}}, socketHandledRequests: 1, socketHandledResponses: 0)
headers: {}
    at Timeout._onTimeout (/Users/hechuan/.s/components/devsapp.cn/devsapp/fc-core/dist/index.js:148:6296)
    at listOnTimeout (node:internal/timers:564:17)
    at processTimers (node:internal/timers:507:7)
hechuan9 commented 1 year ago

有个很奇怪的地方,在log里有一处

Start deploy by @serverless-devs
 - access: default
 - access key id: 1229*********6963

但是这个1229什么的数字应该是账户号

hechuan9 commented 1 year ago

看起来是midway cli的一些问题。

zhangyuang commented 1 year ago

从自己身上找原因,官网文档就是用midway +deploy部署的没有任何问题

hechuan9 commented 1 year ago

我把所有跟ssr和midway的dependency都升到了latest,至少最小范例能deploy了,再研究下大文件...

zhangyuang commented 1 year ago

大文件用 dev Dependencies+ config.whiteList ,如果只在客户端阶段使用那么直接放在dev Dependencies即可不需要配置whiteList

hechuan9 commented 1 year ago

可以关掉了。最后都成功了。解决办法是全局安装了pnpm,然后就算直接引用在dependency里加入react-pdf也没问题。很奇怪。