Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Generated entry JS file for AOT thinks I'm not using AOT

Offen
#430 1 Kommentar 2 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@jasongin arbeitet bereits daran.

Seit 14.3.2025.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Beschreibung

I'm building an AOT module with the following .csproj file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PublishAot>true</PublishAot>
    <PublishNodeModule>true</PublishNodeModule>
    <PublishDir>bin</PublishDir>
    <PackNpmPackage>true</PackNpmPackage>
    <PackageOutputPath>pkg</PackageOutputPath>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.JavaScript.NodeApi" Version="0.9.5" />
    <PackageReference Include="Microsoft.JavaScript.NodeApi.Generator" Version="0.9.5" />
  </ItemGroup>

</Project>

After dotnet publish, I get a valid AOT .dll file with the following .js entry file generated:

// Generated for: NativeModule 1.0.0.0
// Generated by: Microsoft.JavaScript.NodeApi.Generator 0.9.0.0
/* eslint-disable */

const dotnet = require('node-api-dotnet/net8.0');
const path = require('node:path');
// @ts-ignore - https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/65252
const { dlopen, platform, arch } = require('node:process');

const moduleName = path.basename(__filename, __filename.match(/(\.[cm]?js)?$/)[0]);
module.exports = dotnet ? importDotnetModule(moduleName) : importAotModule(moduleName);

function importDotnetModule(moduleName) {
	[...]
}

function importAotModule(moduleName) {
	[...]
}

Note the module.exports = dotnet ? importDotnetModule(moduleName) : importAotModule(moduleName); line which is the culprit here - because I'm using AOT, it's supposed to call importAotModule rather than importDotnetModule. However, I'm not sure how this is supposed to work:

  • If I have node-api-dotnet in my dependencies, require('node-api-dotnet/net8.0') works, i.e. it returns a truthy value, so importDotnetModule gets called (which fails)
  • If I don't have node-api-dotnet in my dependencies (as in the example), the require throws and I can't import the module

I feel I'm missing something here, how am I supposed to "tell" the generator or runtime I'm using AOT?

Vorherrschende Sprache
C#
Sterne
783
Forks
80
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus microsoft/node-api-dotnet

Alle Issues in microsoft/node-api-dotnet

Ähnliche Issues

Weitere Issues zu C#

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.