ialex32x / unity-jsb

It brings Javascript runtime capability to Unity3D by integrating QuickJS.
MIT License
337 stars 41 forks source link

会报错 Module not found: Error: Can't resolve 'Example' #17

Closed JasonLion-CN closed 3 years ago

JasonLion-CN commented 3 years ago

执行 npm run build 会报错:

ERROR in ./Scripts/src/example_main.ts Module not found: Error: Can't resolve 'Example' in 'G:\unity-jsb-git\Scripts\src' @ ./Scripts/src/example_main.ts 4:18-36

ERROR in ./Scripts/src/example_main.ts Module not found: Error: Can't resolve 'jsb' in 'G:\unity-jsb-git\Scripts\src' @ ./Scripts/src/example_main.ts 5:12-26

这里报错会影响编译成功,怎么处理呢。

ialex32x commented 3 years ago

嗯,看到了,是因为之前之前把C#类导出到global中,现在改成模块了,webpack配置没相应调整。 可以先直接命令行 tsc 编译一下(或 tsc --watch),是可以成功的。 webpack配置我另外修改一下。

JasonLion-CN commented 3 years ago

public static JSValue Bind_XmlEscape(JSContext ctx, JSValue this_obj, int argc, JSValue[] argv) { try { if (argc == 0) { string self; if (!js_get_primitive(ctx, this_obj, out self)) { throw new ThisBoundException(); } var ret = SyntaxTree.VisualStudio.Unity.Messaging.StringExtensions.XmlEscape(self); return js_push_primitive(ctx, ret); } throw new NoSuitableMethodException("XmlEscape", argc); } catch (Exception exception) { return JSApi.ThrowException(ctx, exception); } }

-> SyntaxTree.VisualStudio.Unity.Messaging.StringExtensions.XmlEscape(self); 这句报错,没有这个库。是否可以改成: var ret = System.Security.SecurityElement.Escape(self);

ialex32x commented 3 years ago

这是你本地Editor环境下存在这个扩展函数导致的, 可以尝试排除该扩展类的导出:

    public class CustomBinding : AbstractBindingProcess
    {
        ...

        public override void OnPreExporting(BindingManager bindingManager)
        {
            bindingManager.AddTypePrefixBlacklist("SyntaxTree.");
            ...

默认加到 BindingManager 里了, 新提了一个 commit. 类似情况都可以在 OnPreExporting 中做相关操作.