bootsharp icon indicating copy to clipboard operation
bootsharp copied to clipboard

Bundled Javascript module errors due to strict mode

Open torgabor opened this issue 1 year ago • 6 comments

Hi!

I found that after bundling, the created module does not work (dotnet.boot() crashes). This is due to the usage of undeclared identifiers assigned in certain functions. This shouldn't be a problem, but since some bundlers seem to tack on 'use strict'; where they shouldn't, it becomes an issue, and fixing it shouldn't cause any problems.

The offending functions are:

_js_to_mono_obj : result is undeclared bind_method : bodyJs is underclared _handle_exception_and_produce_result_for_call : result is undeclared

torgabor avatar Jul 28 '22 15:07 torgabor

Hi, Those come from .NET runtime's auto-generated JS wrapper. We currently have to use a modified version of 6.0 runtime (due to #20) and are patching the wrapper to resolve some critical issues, but otherwise I'd like to refrain from patching it further, as there are plans to drop the modified runtime as soon as those critical issues are resolved (hopefully in .NET 7.0 or 8.0).

The strict violations in the wrapper will hopefully be also resolved at that point (or maybe they already are).

elringus avatar Jul 28 '22 15:07 elringus

Thanks, but this is kind of a deal-breaker for us - we are using DotNetJS right now. Do you have a workaround in mind? I mean, this is your library, and your call, but I feel like fixing this bug wouldn't have any negative impacts. Down the road, there should be a proper fix for this.

Edit: I feel like using DotNetJS as a library is a valuable use case for others as well.

torgabor avatar Jul 28 '22 15:07 torgabor

For a temporary workaround (until we migrate to the next .NET runtime), I'd suggest using bundlers that can work with this. For example, I'm using webpack in various scenarios (node, webworker extension for vscode, react) and do not encounter any issues.

If you still want to patch the wrapper check out https://github.com/Elringus/DotNetJS/blob/8dee89d997da1158c1ea6830435a1dabc6608924/JavaScript/scripts/compile-runtime.sh#L13 for a reference.

elringus avatar Jul 28 '22 15:07 elringus

Thanks I'll look into that. Unfortunately I can't really change the bundler, since it's already an established project. I did a PR if you decide to change your mind.

(https://github.com/Elringus/DotNetJS/pull/81)

torgabor avatar Jul 28 '22 15:07 torgabor

Created a new PR with your feedback

(https://github.com/Elringus/DotNetJS/pull/82)

torgabor avatar Jul 28 '22 17:07 torgabor

This issue is stale because it has been open 14 days with no activity. It will be automatically closed in 7 days.

github-actions[bot] avatar Aug 12 '22 04:08 github-actions[bot]