类型“Context”上不存在属性“http”

我拉去了别人的插件进行开发
使用–force忽略依赖问题,然后发现类型“Context”上不存在属性“http”
但是yarn dev调试没有问题,直到我npm run build就报错了。
我不知道应该如何解决这个问题

1 个赞

Check

1 个赞
// tsconfig
{
  "compilerOptions": {
    "rootDir": "src",
    "outDir": "lib",
    "target": "es2022",
    "module": "esnext",
    "declaration": true,
    "composite": true,
    "incremental": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "moduleResolution": "bundler",
    "jsx": "react-jsx",
    "jsxImportSource": "@satorijs/element",
    "types": [
      "node",
      "yml-register/types"
    ]
  },
  "include": [
    "src",
    "src/data/songs.json"
  ]
}

我按照您提供的方法修改了tsconfig文件
build成功,但是yarn start使用插件失败
我发现生成的js代码仍然是ts的格式
比如仍然使用了import而不是require
报错如下

loader Error [ERR_REQUIRE_ESM]: require() of ES Module /home/mqnu/program/koishi-app/external/phigros-redo/lib/index.js from /home/mqnu/program/koishi-app/node_modules/@koishijs/loader/lib/index.js not supported.
                        Instead change the require of /home/mqnu/program/koishi-app/external/phigros-redo/lib/index.js in /home/mqnu/program/koishi-app/node_modules/@koishijs/loader/lib/index.js to a dynamic import() which is available in all CommonJS modules.
                            at Proxy.import (/home/mqnu/program/koishi-app/node_modules/@koishijs/loader/lib/index.js:182:12)
                            at Proxy.resolve (/home/mqnu/program/koishi-app/node_modules/@koishijs/loader/lib/shared.js:267:51)
                            at Proxy.forkPlugin (/home/mqnu/program/koishi-app/node_modules/@koishijs/loader/lib/shared.js:287:31)
                            at Proxy.reload (/home/mqnu/program/koishi-app/node_modules/@koishijs/loader/lib/shared.js:319:27)
                            at Proxy.reload (/home/mqnu/program/koishi-app/node_modules/@koishijs/plugin-config/lib/shared/index.js:275:23)
1 个赞

emitDeclarationOnly 呢?

1 个赞

是的,就是这个没有写,问题已解决,非常感谢 :rofl:

2 个赞