Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#430 1 bình luận 2 reaction 1 người được giao Xem trên GitHub

@jasongin đang làm issue này rồi.

Từ ngày 14/3/2025.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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?

Ngôn ngữ chính
C#
Star
783
Fork
80
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/node-api-dotnet

Tất cả issue của microsoft/node-api-dotnet

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.