You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/apis/LanguageSupport.md
+63Lines changed: 63 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,69 @@ Currently, LSE supports writing plugins in the following languages:
30
30
- Use `jsdebug` command in the BDS console to enter and exit the QuickJs interactive command line environment. This
31
31
feature facilitates some simple testing when writing plugins
32
32
33
+
### QuickJS ESModule Path Resolution Behavior
34
+
35
+
The **ScriptX** used by LegacyScriptEngine is forked from the upstream **Tencent/ScriptX** project, with additional features added on top of it (such as Python backend support).
36
+
37
+
In the QuickJS backend, ScriptX uses the default `module loader` provided in **quickjs-libc.h**.
38
+
This loader causes the behavior of QuickJS ESModule when resolving the **entry module** to differ from the standard ESModule specification.
39
+
40
+
Specifically, when loading the **entry module**, the loader sets the module's base path to the **current working directory (CWD)** — which is typically the directory where the server executable is located — rather than the directory where the script file resides.
41
+
42
+
As a result, relative `import` paths in the entry file are resolved differently from standard ESModule behavior.
43
+
44
+
Assume the following plugin directory structure:
45
+
46
+
```
47
+
c:/bds
48
+
bedrock_server_mod.exe
49
+
plugins/
50
+
your_plugin/
51
+
manifest.json
52
+
index.js
53
+
command/
54
+
command.js
55
+
```
56
+
57
+
Entry file **index.js**:
58
+
```js
59
+
import { initCommand } from"./command/command.js"
60
+
61
+
initCommand();
62
+
```
63
+
64
+
In this case, QuickJS resolves the entry module's import.meta.url as:
65
+
66
+
```
67
+
file:///c:/bds
68
+
```
69
+
70
+
instead of:
71
+
72
+
```
73
+
file:///c:/bds/plugins/your_plugin
74
+
```
75
+
76
+
Therefore `./command/command.js` cannot be resolved correctly, causing the plugin to fail to load.
77
+
78
+
For example, QuickJS may produce an error similar to the following (original log output):
0 commit comments