zombieyang / puerts_unity_webgl_demo

在Unity里用Typescript写小游戏/Web游戏
BSD 3-Clause "New" or "Revised" License
190 stars 68 forks source link

[unity] mockRequire死循环 #35

Closed Halliwood closed 1 year ago

Halliwood commented 1 year ago

error log | 日志或报错信息

Exception: Maximum call stack size exceeded at Puerts.JsEnv.ExecuteModule (System.String filename) [0x00000] in <00000000000000000000000000000000>:0

context | 编译/运行环境

对于比较复杂的import关系,比如A import B, B import C, C import A...,就可能出现requrie死循环,如下图

image

tsconfig.target: es2016 tsconfig.module: CommonJS

how to reproduce | 复现步骤

more | 其他

image 如上图,我把Javascripts~/PuertsDLLMork/index.ts改了一下,暂时解决了这个问题

PUERTS_JS_RESOURCES[specifier](result.exports, (specifierTo: string)=> {
    return mockRequire(normalize(specifier, specifierTo));
}, result)
executeModuleCache[specifier] = result.exports;

改成

executeModuleCache[specifier] = result.exports;
PUERTS_JS_RESOURCES[specifier](result.exports, (specifierTo: string)=> {
    return mockRequire(normalize(specifier, specifierTo));
}, result)