C# AOT compilation not setting "dotnet" to undefined

Open Beginner friendly
#484 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
csharp
Domain
build-system

Research direction

Start in NodeApi.targets and inspect the inline task that rewrites the generated JavaScript loader. Reproduce an AOT compilation and check the resulting loader for the netX.X import form shown in the issue. Done means the AOT output uses const dotnet = undefined; instead of importing node-api-dotnet/netX.X.

Written by the indexing model from the issue text.

Description

Hello,

When compiling the module as AOT module then the resulting js module loaders is incorrect because:
import dotnet from 'node-api-dotnet/net10.0';
should have been:
const dotnet = undefined;

Poking around in the source code the problem is in NodeApi.targets which does:

    <Task>
      <Using Namespace="System.IO" />
      <Code Type="Fragment" Language="cs">
      <![CDATA[
        string js = File.ReadAllText(TargetFile);
        js = js.Replace("const dotnet = require('node-api-dotnet');", "const dotnet = undefined;");
        js = js.Replace("import dotnet from 'node-api-dotnet';", "const dotnet = undefined;");
        if (!IncludeRidSubpath) js = js.Replace("rid, ", "");
        File.WriteAllText(TargetFile, js);
      ]]>
      </Code>
    </Task>

but it should now replace "node-api-dotnet/netX.X" instead of just "node-api-dotnet"

Thanks!

Dominant language
C#
Stars
783
Forks
80
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/node-api-dotnet

All issues in microsoft/node-api-dotnet

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.