microsoft / microsoft/node-api-dotnet

Example "aot-module" fails with [ERR_MODULE_NOT_FOUND]: Cannot find package 'node-api-dotnet'

Open
#461 0 comments 1 reaction 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

To repro, I'm on main branch commit 11c5a48.

I'm following the instructions at examples/aot-module/README.md:

cd examples\aot-module
dotnet pack ../..
dotnet publish
node example.js

And I get this error:

node:internal/modules/package_json_reader:268
  throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
        ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'node-api-dotnet' imported from D:\node-api-dotnet\examples\aot-module\bin\aot-module.js
    at Object.getPackageJSONURL (node:internal/modules/package_json_reader:268:9)
    at packageResolve (node:internal/modules/esm/resolve:768:81)
    at moduleResolve (node:internal/modules/esm/resolve:854:18)
    at defaultResolve (node:internal/modules/esm/resolve:984:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:685:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:634:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:617:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:273:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:135:49) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v22.14.0

I found I could fix this by making this change in bin/aot-module.js:

// Removed this line:
//import dotnet from 'node-api-dotnet/net8.0'; 

// Added this line:
const dotnet = undefined;

And then it works fine:

Hello .NET AOT!

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 by running the commands in examples/aot-module/README.md on the reported commit and inspect bin/aot-module.js, especially its node-api-dotnet import. The issue is done when the documented commands run successfully and print "Hello .NET AOT!" without manually replacing the import.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, javascript, node.js
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.