Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: 两个问题 #1339

Closed
FurryRbl opened this issue Jan 19, 2024 · 6 comments
Closed

Bug: 两个问题 #1339

FurryRbl opened this issue Jan 19, 2024 · 6 comments
Labels
bug BUG

Comments

@FurryRbl
Copy link

FurryRbl commented Jan 19, 2024

Describe the bug

问题1:

❯ yarn dev
yarn run v1.22.21
$ node ./src/main.js
P:\Xiying\koishi\node_modules\cordis\lib\index.cjs:614
    throw new Error('invalid plugin, expect function or object with an "apply" method, received ' + typeof plugin);
          ^

Error: invalid plugin, expect function or object with an "apply" method, received object
    at Proxy.resolve (P:\Xiying\koishi\node_modules\cordis\lib\index.cjs:614:11)
    at Proxy.plugin (P:\Xiying\koishi\node_modules\cordis\lib\index.cjs:653:10)
    at file:///P:/Xiying/src/main.js:10:5
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async loadESM (node:internal/process/esm_loader:34:7)
    at async handleMainPromise (node:internal/modules/run_main:113:12)

Node.js v20.10.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

问题2”:

❯ yarn dev
yarn run v1.22.21
$ node ./src/main.js
Done in 0.92s.

Steps to reproduce

问题1代码:

import { Context } from "../koishi/packages/koishi/lib/index.mjs";
import * as echo from "@koishijs/plugin-echo";
import console from "@koishijs/plugin-console";
import * as sandbox from "@koishijs/plugin-sandbox";

const app = new Context({
	port: 6200,
});

app.plugin(console);
app.plugin(sandbox);
app.plugin(echo);

app.start();

问题二代码:

import { Context } from "../koishi/packages/koishi/lib/index.mjs";
import * as echo from "@koishijs/plugin-echo";
import console from "@koishijs/plugin-console";
import * as sandbox from "@koishijs/plugin-sandbox";

const app = new Context({
	port: 6200,
});

//app.plugin(console);
app.plugin(sandbox);
app.plugin(echo);

app.start();

Expected behavior

正常运行并出现6200端口

Screenshots

No response

Versions

  • OS: Windows 10 专业工作站版 [64 位](10.0.19044.0)
  • Platform: Koishi
  • Node version: v20.10.0
  • Koishi version: 9710a7e

Additional context

如果采用CJS写法则不会出现问题1但仍然会出现问题2
如果采用CJS和TS写法则不会出现问题1但仍然会出现问题2

@FurryRbl FurryRbl added the bug BUG label Jan 19, 2024
@shigma
Copy link
Member

shigma commented Jan 19, 2024

关于问题 2:port 是 @koishijs/plugin-server 的配置项。

import server from '@koishijs/plugin-server'

app.plugin(server, {
  port: 6200,
})

为什么不加载 server 就会直接退出呢?因为 node 进程会检测是否有持续占用的 handle,没有 handle 的情况下就会直接退出,开了 server 就不会退出了。

@FurryRbl
Copy link
Author

关于问题 2:port 是 @koishijs/plugin-server 的配置项。

import server from '@koishijs/plugin-server'

app.plugin(server, {
  port: 6200,
})

为什么不加载 server 就会直接退出呢?因为 node 进程会检测是否有持续占用的 handle,没有 handle 的情况下就会直接退出,开了 server 就不会退出了。

感觉可以但我试不了会抛出问题1的错误。。。。其实我都是看文档部署的

@shigma
Copy link
Member

shigma commented Jan 26, 2024

已经复现此问题,似乎是 Console 构建结果的问题。

import Console from '@koishijs/plugin-console'

app.plugin(Console) // 类型正常,运行报错
app.plugin(Console.default) // 类型报错,运行正常

我们会尽快修复。

@FurryRbl
Copy link
Author

已经复现此问题,似乎是 Console 构建结果的问题。

import Console from '@koishijs/plugin-console'

app.plugin(Console) // 类型正常,运行报错
app.plugin(Console.default) // 类型报错,运行正常

我们会尽快修复。

幸苦了

@shigma
Copy link
Member

shigma commented Jan 26, 2024

刚刚修了 server 的部分,console 的部分稍等。

shigma added a commit that referenced this issue Jan 26, 2024
shigma added a commit to koishijs/webui that referenced this issue Jan 26, 2024
@shigma
Copy link
Member

shigma commented Jan 26, 2024

发了前前后后十几个版本,如果之后还有类似的问题可以同样提这里。

用不了的话尝试一下 ffff['default'] 的写法,ts 不会报错。

CyanChanges pushed a commit to CyanForks/webui that referenced this issue Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug BUG
Projects
None yet
Development

No branches or pull requests

2 participants