25 min read

不知道怎么想的,我在某一天突然想要把我的b站动态嵌入的我的博客里

于是我问 opencode 里的 deepseek 我该怎么做,她说,用 cf worker 代理,用 RSShub ,用……

我说你不必再说,用RSShub,

RSShub 方案

但是这个傻缺没有发现 vercel 默认配置和我电脑本地用的 node 版本都是 24.x ,而 RSShub 官方公共实例用的是 22.x

那这会导致我在构建时盯着日志时不时弹出来个 error 时不时弹出来个 warning

最后统计有 195 个 error,WDF

而且 RSShub b站动态的路由时坏的

https://rsshub.app/bilibili/user/dynamic/2267573

返回的 error message

Error: [unenv] fs.readFileSync is not implemented yet!

这是 vercel 记录的日志

Error [ERR_REQUIRE_ESM]: require() of ES Module /var/task/node_modules/.pnpm/htmlparser2@12.0.0/node_modules/htmlparser2/dist/index.js from /var/task/node_modules/.pnpm/sanitize-html@2.17.6/node_modules/sanitize-html/index.js not supported.
Instead change the require of /var/task/node_modules/.pnpm/htmlparser2@12.0.0/node_modules/htmlparser2/dist/index.js in /var/task/node_modules/.pnpm/sanitize-html@2.17.6/node_modules/sanitize-html/index.js to a dynamic import() which is available in all CommonJS modules.
at /opt/rust/nodejs.js:2:13533
at Module.Vn (/opt/rust/nodejs.js:2:13911)
at e.<computed>.st._load (/opt/rust/nodejs.js:2:13503)
at s (/opt/rust/bytecode.js:2:1110) {
code: 'ERR_REQUIRE_ESM'
}
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.
Error [ERR_REQUIRE_ESM]: require() of ES Module /var/task/node_modules/.pnpm/htmlparser2@12.0.0/node_modules/htmlparser2/dist/index.js from /var/task/node_modules/.pnpm/sanitize-html@2.17.6/node_modules/sanitize-html/index.js not supported.
Instead change the require of /var/task/node_modules/.pnpm/htmlparser2@12.0.0/node_modules/htmlparser2/dist/index.js in /var/task/node_modules/.pnpm/sanitize-html@2.17.6/node_modules/sanitize-html/index.js to a dynamic import() which is available in all CommonJS modules.
at /opt/rust/nodejs.js:2:13533
at Module.Vn (/opt/rust/nodejs.js:2:13911)
at e.<computed>.st._load (/opt/rust/nodejs.js:2:13503)
at s (/opt/rust/bytecode.js:2:1110) {
code: 'ERR_REQUIRE_ESM'
}
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.
Error [ERR_REQUIRE_ESM]: require() of ES Module /var/task/node_modules/.pnpm/htmlparser2@12.0.0/node_modules/htmlparser2/dist/index.js from /var/task/node_modules/.pnpm/sanitize-html@2.17.6/node_modules/sanitize-html/index.js not supported.
Instead change the require of /var/task/node_modules/.pnpm/htmlparser2@12.0.0/node_modules/htmlparser2/dist/index.js in /var/task/node_modules/.pnpm/sanitize-html@2.17.6/node_modules/sanitize-html/index.js to a dynamic import() which is available in all CommonJS modules.
at /opt/rust/nodejs.js:2:13533
at Module.Vn (/opt/rust/nodejs.js:2:13911)
at e.<computed>.st._load (/opt/rust/nodejs.js:2:13503)
at s (/opt/rust/bytecode.js:2:1110) {
code: 'ERR_REQUIRE_ESM'
}
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.

以下是鲸鱼小姐给出的分析

  • sanitize-html@2.17.6 内部用 require(‘htmlparser2’)(CJS)
  • 它依赖的 htmlparser2@12.0.0 是纯 ESM,不让 require()
  • Vercel 构建时没打包依赖(tsdown-vercel.config.ts 里 onlyBundle: false),运行时直接炸

于是我就让鲸鱼小姐去修复

嗯,不对,怎么鲸鱼小姐修完还是 error 啊,哦,原来是要装 patchright 啊

pnpm exec patchright install chromium

好了该部署到 vercel 上了

来让我看看

This Serverless Function has crashed.

Your connection is working correctly.

Vercel is working correctly.

500: INTERNAL_SERVER_ERROR
Code: FUNCTION_INVOCATION_FAILED
ID: iad1::g9ll9-1784364368322-cef9ffd09259

If you are a visitor, contact the website owner or try again later.
If you are the owner, learn how to fix the error and check the logs.

这又是怎么了呢

这不得不又请出我们的鲸鱼小姐

确认了——当前 lockfile 里 sanitize-html@2.17.6 还是解析到 htmlparser2: 12.0.0(第 11352 行),pnpm 10.34.4 确实不吃任何形式的 overrides

Vercel 部署时跑 pnpm install –frozen-lockfile,严格按照 lockfile 装依赖,所以 serverless runtime 加载 sanitize-html → require(htmlparser2@12.0.0) → 炸了

那怎办呢sanitize-html 降级到 2.16.0

好了,既然已经把bug改完了,那就把RSShub对接到博客本地的开发环境吧

error: Error in /bilibili/user/dynamic/2267573: CaptchaError: 遇到源站风控校验,请稍后再试
at Object.handler (C:\Users\Admin\Documents\rsshub\RSSHub\lib\routes\bilibili\dynamic.ts:299:19)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async wrappedHandler (C:\Users\Admin\Documents\rsshub\RSSHub\lib\registry-helpers.ts:186:38)
at async dispatch (file:///C:/Users/Admin/Documents/rsshub/RSSHub/node_modules/.pnpm/hono@4.12.30/node_modules/hono/dist/compose.js:22:17)
at async bridge (C:\Users\Admin\Documents\rsshub\RSSHub\lib\registry-dev.ts:43:9)
at async dispatch (file:///C:/Users/Admin/Documents/rsshub/RSSHub/node_modules/.pnpm/hono@4.12.30/node_modules/hono/dist/compose.js:22:17)
at async file:///C:/Users/Admin/Documents/rsshub/RSSHub/node_modules/.pnpm/hono@4.12.30/node_modules/hono/dist/hono-base.js:306:25
at async middleware (C:\Users\Admin\Documents\rsshub\RSSHub\lib\registry-dev.ts:107:30)
at async dispatch (file:///C:/Users/Admin/Documents/rsshub/RSSHub/node_modules/.pnpm/hono@4.12.30/node_modules/hono/dist/compose.js:22:17)
at async middleware (C:\Users\Admin\Documents\rsshub\RSSHub\lib\middleware\cache.ts:72:9)

到现在,就只能配置 cookie 了

打开浏览器的 F12 > network > 点击一个请求,找到 cookie 那一栏,将那一大坨都复制下来

来到 RSShub 项目根目录,新建一个 .env 文件,按照下面的格式写入内容

BILIBILI_COOKIE=刚刚复制的 bilibili cookie

来浏览器看看,没问题的

交给 AI 还是运行不了

不是我跨域请求也有啊

cf worker 方案

在经历前面的失败后,我把RSShub方案换成了cf worker

在和鲸鱼小姐提出了我的需求之后也是很快的给出了

在 GitHub 上查看

当然问题和上一个一样

来浏览器看看,没问题的

交给 AI 还是运行不了

于是……

@ikenxuan/amagi 方案

这是一个多平台社交媒体 SDK,支持 B 站、抖音、快手、小红书这四个平台

@ikenxuan/amagi 开源项目地址

但你总不能在用户浏览器上跑吧,而且也跑不了,所以……

在 GitHub 上查看

又一个 worker 我不明白,我为什么又做一个出来,但这个也被我放弃了

通过 CI 获取

这个就是目前生产环境下运行的获取 b 站动态的方法

在 GitHub 查看

这个就是通过浏览器自动化工具获取指定的,但这个工具还有点bug,等会我去更新一下

反正目前是有数据了,就让鲸鱼小姐写客户端 js

用不了……用不了……用不了……欸不是怎么总是用不了

我不知道怎想的,去点一下友链里的申请,点一下归档里的搜索

全都用不了

合着是整个客户端 js 都坏了是吧,没办法,只能让鲸鱼小姐重写整个脚本

现在的话 dynamic 是可以正常运行了,不会出现一直显示加载中了

如果想体验可以访问

访问动态页