microsoft / microsoft/node-api-dotnet

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.

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

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!

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.

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.