Error related to global.node_api_dotnet.require when trying to use streams
@jasongin 已經在處理了。
開始於 2025年3月14日。
評估
這個 Issue 還沒有評估資料。
描述
I tried a simple example to test out using streams:
[JSExport]
public class Class1
{
public static Stream HelloStream(string greeter)
{
string message = "hello " + greeter;
byte[] messageBytes = Encoding.UTF8.GetBytes(message);
MemoryStream stream = new MemoryStream(messageBytes);
stream.Position = 0;
return stream;
}
}
Oddly, this throws an error:
const MyModule = require('./MyModule/bin/MyModule');
const stream = MyModule.Class1.helloStream('world'); // throws
This is the error:
Error: The require function was not found on the global node_api_dotnet object. Set `global.node_api_dotnet.require` before loading the module.
at Microsoft.JavaScript.NodeApi.Interop.JSRuntimeContext.get_RequireFunction() + 0x35f
at Microsoft.JavaScript.NodeApi.Interop.JSRuntimeContext.<>c__DisplayClass51_0.<Import>b__0(ValueTuple`2 _) + 0x1c4
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey, Func`2) + 0xdf
at Microsoft.JavaScript.NodeApi.Interop.JSRuntimeContext.Import(String, String, Boolean) + 0xd7
at Microsoft.JavaScript.NodeApi.Interop.JSRuntimeContext.<>c__DisplayClass51_0.<Import>b__0(ValueTuple`2 _) + 0x33e
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey, Func`2) + 0xdf
at Microsoft.JavaScript.NodeApi.Interop.JSRuntimeContext.Import(String, String, Boolean) + 0xd7
at Microsoft.JavaScript.NodeApi.Interop.NodeStream.CreateProxy(Stream) + 0x5a
at Microsoft.JavaScript.NodeApi.Interop.JSRuntimeContext.<>c__DisplayClass37_0`1.<GetOrCreateObjectWrapper>b__0() + 0x43
at Microsoft.JavaScript.NodeApi.Interop.JSRuntimeContext.GetOrCreateObjectWrapper[T](T, Func`1) + 0xd6
at Microsoft.JavaScript.NodeApi.Interop.JSRuntimeContext.GetOrCreateObjectWrapper[T](T) + 0x8d
at Microsoft.JavaScript.NodeApi.Generated.Module.MyModule_Class1_HelloStream(JSCallbackArgs __args) + 0xa5
at MyModule!<BaseAddress>+0x145159
at Microsoft.JavaScript.NodeApi.JSValue.InvokeCallback[TDescriptor](JSRuntime.napi_env, JSRuntime.napi_callback_info, JSValueScopeType, Func`2) + 0x1bc
at Object.<anonymous> (C:\Users\User\project\index.js:5:37)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
error Command failed with exit code 1.
I was able to fix it by adding global.node_api_dotnet = { require } before requiring the module, but this feels like a hack - am I doing something wrong?
- 主要語言
- C#
- 星號
- 788
- 分支
- 80
- 平均合併
- 34 分鐘
- 30 天內合併 PR
- 1
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
microsoft/node-api-dotnet 的其他 Issue
-
難度 1/5 1-3 小時 新手友好度 88/100
microsoft/node-api-dotnet#484 · 1 則留言 ·
-
Embedding args occasionally get trailing garbage on .NET (missing null terminator on a pooled buffer)可能已有人在做 @tolmachev-pravo 於 103 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 82/100
microsoft/node-api-dotnet#481 ·
-
`JSError.ThrowTypeError` / `ThrowRangeError` / `ThrowSyntaxError` throw a plain `Error`可能已有人在做 @r-Larch 於 4 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 58/100
microsoft/node-api-dotnet#509 ·
-
`PooledBuffer.FromStringUtf8`/`FromSpanUtf8` never write the NUL terminator → garbage in JS error messages and linked module names on .NET可能已有人在做 @r-Larch 於 4 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 30/100
microsoft/node-api-dotnet#508 ·
-
JSError.ThrowError(Exception) aborts the process when a Worker terminates during a .NET call可能已有人在做 @GalaxiasKyklos 於 12 天前認領。 未關閉
難度 4/5 3-5 天 新手友好度 18/100
microsoft/node-api-dotnet#505 ·
查看 microsoft/node-api-dotnet 的全部 Issue
相似的 Issue
-
area:jobads-cv BE P3
難度 1/5 1-3 小時 新手友好度 74/100
klasolsson81/jobbliggaren#2240 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
k2-fsa/sherpa-onnx#4100 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
unoplatform/uno.check#591 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 75/100
weaviate/csharp-client#378 ·
-
area:repo devops elsa 3 prio medium triaged
難度 2/5 1-3 小時 新手友好度 72/100
elsa-workflows/elsa-core#9098 ·
維護者通常 1 天內回覆