koishijs / koishi

Cross-platform chatbot framework made with love
https://koishi.chat
MIT License
4.53k stars 246 forks source link

Bug: SyntaxError: The requested module '@koishijs/loader' does not provide an export named 'default' #1336

Closed FurryRbl closed 10 months ago

FurryRbl commented 10 months ago

Describe the bug

运行时出现以下错误:

❯ yarn dev
yarn run v1.22.21
$ node ./src/main.js
file:///P:/Xiying/node_modules/koishi/lib/index.mjs:2
import Loader from "@koishijs/loader";
       ^^^^^^
SyntaxError: The requested module '@koishijs/loader' does not provide an export named 'default'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:132:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:214:5)
    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.

Steps to reproduce

./src/main.js代码:

import { Context } from "koishi";
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

Additional context

package.json文件内容:

{
    "name": "test",
    "version": "1.0.0",
    "description": "测试",
    "type": "module",
    "license": "MPL-2.0",
    "private": true,
    "main": "./src/main.js",
    "author": {
        "name": "SharpIce",
        "email": "VupRbl@163.com",
        "url": "https://SharpIce.top"
    },
    "engines": {
        "node": ">=20"
    },
    "scripts": {
        "lint": "eslint --fix .",
        "clean": "rimraf build/",
        "pre": "prettier . --write",
        "dev": "node ./src/main.js"
    },
    "devDependencies": {
        "eslint": "^8.48.0",
        "eslint-config-prettier": "^9.0.0",
        "eslint-plugin-prettier": "^5.0.0",
        "prettier": "^3.0.2",
        "rimraf": "^5.0.1"
    },
    "dependencies": {
        "koishi": "^4.16.4",
        "@koishijs/plugin-console": "^5.25.6",
        "@koishijs/plugin-echo": "^2.2.5",
        "@koishijs/plugin-sandbox": "^3.2.4"
    }
}
CyanChanges commented 10 months ago

@koishijs/loader 用 esm 会 import 到 shared 而不是 index,但是 shared 没有 default export,index 有 default export

用 common js 的 require 应该可以,建议先换成 require(

或者编译为 commonjs(

shigma commented 10 months ago

好像确实是楼上说的问题。我下个版本会尝试解决(本周内)。