JS调用KOISHI,报错

代码:

const { app, BrowserWindow } = require('electron')
const path = require('node:path')
const Context  = require('koishi')
const console = require('@koishijs/plugin-console')

const createWindow = () => {
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    }
  })

  // 加载 index.html
  mainWindow.loadFile('src/index.html')

  // 打开开发工具
  // mainWindow.webContents.openDevTools()
}


// 创建一个 Koishi 应用
const ctx = new Context({
  port: 5140
})

app.whenReady().then(() => {
  createWindow()
  // 启用上述插件
  ctx.plugin(console) // 提供控制台
  // 启动应用
  ctx.start()

  app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) {
      createWindow()
    }
  })
})

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

错误:

App threw an error during load
TypeError: Context is not a constructor
at Object. (F:\OpenSource\Lanqi-Koishi\main.js:24:13)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions…js (node:internal/modules/cjs/loader:1311:10)
at Module.load (node:internal/modules/cjs/loader:1098:32)
at Module._load (node:internal/modules/cjs/loader:945:12)
at c._load (node:electron/js2c/node_init:2:13672)
at cjsLoader (node:internal/modules/esm/translators:288:17)
at ModuleWrap. (node:internal/modules/esm/translators:234:7)
at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)

3 个赞

You might need to investigate what type is the Context. You could utilise a single console.log or a debugger to achieve it.

3 个赞

解决方案:别用 GPT 写代码。

这个代码中存在的问题任何读了文档的人都写不出来,所以我不会解答。

7 个赞

你在写√8呢,你自己看得懂吗

2 个赞

我的懒弃 Koishi 何时复活,我已经等不及了

2 个赞