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: SyntaxError: The requested module '@koishijs/loader' does not provide an export named 'default' #1336

Closed
FurryRbl opened this issue Jan 17, 2024 · 2 comments
Labels
bug BUG

Comments

@FurryRbl
Copy link

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

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

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"
	}
}
@FurryRbl FurryRbl added the bug BUG label Jan 17, 2024
@CyanChanges
Copy link

CyanChanges commented Jan 17, 2024

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

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

或者编译为 commonjs(

@shigma
Copy link
Member

shigma commented Jan 17, 2024

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

@shigma shigma closed this as completed in 9710a7e Jan 18, 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

3 participants