deno_core
deno_core copied to clipboard
import an mjs file twice at the same time cause an error
Version: Deno 2.3.6
if you load an mjs file twice at the same time youll get an error like this:
Skipping fount update due to .noupdate file
deno 2.3.1+92cdce1
standing by...
fo-fo-fo-fo-fo-fount!
正在重启用户 steve02081504 的 Shell discordbot 任务:GentianAphrodite
HTTP 服务器运行在 http://localhost:8931
运行 shell preload 作为 steve02081504,参数:["chars","GentianAphrodite"]
Socket 错误: Error: read ECONNRESET
steve02081504 chars GentianAphrodite
Trace
at loadPartBase (file:///C:/Users/steve02081504/workstation/fount/src/server/parts_loader.mjs:240:11)
at async Object.LoadChar [as chars] (file:///C:/Users/steve02081504/workstation/fount/src/server/managers/char_manager.mjs:27:15)
error: Uncaught (in promise) ReferenceError: Cannot access 'default' before initialization
const part = (await import(url.pathToFileURL(path + '/main.mjs'))).default
^
at baseMjsPartLoader (file:///C:/Users/steve02081504/workstation/fount/src/server/parts_loader.mjs:72:69)
at async Loader (file:///C:/Users/steve02081504/workstation/fount/src/server/parts_loader.mjs:200:16)
at async loadPartBase (file:///C:/Users/steve02081504/workstation/fount/src/server/parts_loader.mjs:232:59)
at async Object.LoadChar [as chars] (file:///C:/Users/steve02081504/workstation/fount/src/server/managers/char_manager.mjs:27:15)
Even if the second load is not caused by loading mjs itself (in other words, it does not constitute a self-reference), it will cause an error. I would expect both promises to wait until the mjs file is loaded.
ref: https://github.com/denoland/deno/issues/29123
code for repo:
~ >cat ~/a.mjs
await new Promise(resolve => setTimeout(resolve, 3000));
export default "yeah!";
~ >cat ~/b.mjs
while(true) {
import('./a.mjs').then(m => m.default);
await new Promise(resolve => setTimeout(resolve, 100));
}
~ >deno run b.mjs
error: Uncaught (in promise) ReferenceError: Cannot access 'default' before initialization
import('./a.mjs').then(m => m.default);
^
at file:///C:/Users/steve02081504/b.mjs:2:32
at eventLoopTick (ext:core/01_core.js:217:9)
bun is okey in test
Here is what's going on
https://excalidraw.com/#json=nnERNVjOITV4oQYI62X_o,UEFR9JBRcqgytvjkKqUjwg
A solution would be store a promise, and return that promise