mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 21:12:49 +08:00
A loose `^2.2.10` range let npm pull a newer build of the QQ Music API. The library went ESM in 2.3.x: an ESM-only 2.3.0/2.3.1 throws ERR_REQUIRE_ESM on load, so the embedded server never binds port 3200 and every QQ request (including /getQQLoginQr) fails downstream with ECONNREFUSED — the QR code never appears and cookies look broken. - Pin to `~2.4.0` (verified: loads via the bot's native ESM import, exposes the Koa app, and every endpoint qq.ts calls returns the exact shapes it parses — QR, recommend, lyric, play, playlist detail). Blocks the broken 2.3.0/2.3.1 and any future 2.5 migration. NOTE: 2.4.x requires Node >=20.17 (or >=22.9). - Add describeQqApiStartupError(): on startup failure, log an actionable error (ERR_REQUIRE_ESM → version-pin hint; engine mismatch → Node-upgrade hint) instead of a generic warning, so this is obvious from the logs next time. - README: troubleshooting entry for "QQ 二维码不弹 / 登录失败 / cookie 无法使用" and the version/Node note in the dependency table. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { describeQqApiStartupError } from "./api-server.js";
|
|
|
|
describe("describeQqApiStartupError", () => {
|
|
it("flags ERR_REQUIRE_ESM by error code with version-pin guidance", () => {
|
|
const hint = describeQqApiStartupError({ code: "ERR_REQUIRE_ESM", message: "..." });
|
|
expect(hint).toMatch(/ERR_REQUIRE_ESM/);
|
|
expect(hint).toMatch(/~2\.4\.0/);
|
|
expect(hint).toMatch(/~2\.2\.10/);
|
|
});
|
|
|
|
it("flags ERR_REQUIRE_ESM by message when the code is absent", () => {
|
|
const hint = describeQqApiStartupError(
|
|
new Error("require() of ES Module .../@sansenjian/qq-music-api/dist/index.js not supported")
|
|
);
|
|
expect(hint).toMatch(/incompatible @sansenjian\/qq-music-api/);
|
|
});
|
|
|
|
it("flags a Node engine mismatch with a Node-upgrade hint", () => {
|
|
const hint = describeQqApiStartupError(new Error("Unsupported engine: requires Node >=20.17"));
|
|
expect(hint).toMatch(/Node >=20\.17/);
|
|
expect(hint).toMatch(/~2\.2\.10/);
|
|
});
|
|
|
|
it("returns null for an unrelated startup error (falls back to the generic warning)", () => {
|
|
expect(describeQqApiStartupError(new Error("EADDRINUSE: port in use"))).toBeNull();
|
|
expect(describeQqApiStartupError(undefined)).toBeNull();
|
|
expect(describeQqApiStartupError(null)).toBeNull();
|
|
});
|
|
});
|