Error related to global.node_api_dotnet.require when trying to use streams
@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 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?
- Ngôn ngữ chính
- C#
- Star
- 785
- 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
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/node-api-dotnet
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
microsoft/node-api-dotnet#484 ·
-
Embedding args occasionally get trailing garbage on .NET (missing null terminator on a pooled buffer)Có thể đã có người làm @tolmachev-pravo đã nhận 81 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
microsoft/node-api-dotnet#481 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 82/100
microsoft/node-api-dotnet#502 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
microsoft/node-api-dotnet#486 · 1 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
microsoft/node-api-dotnet#483 · 1 bình luận · 1 reaction ·
Tất cả issue của microsoft/node-api-dotnet
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
elsa-workflows/elsa-core#8593 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
WebSocket upgrade check is case-sensitive for `Upgrade`Có thể đã có người làm @S0CloseYetS0Far đã nhận hôm nay. Đang mởbug good first issue severity:low
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
-
example mod Controller SupportĐang mởNEW ISSUE Requestor-TML Maintainers Type: Change/Feature Request
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
tModLoader/tModLoader#5476 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Issue-Enhancement Needs-Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
PowerShell/PowerShell#28138 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
SubtitleEdit/subtitleedit#15600 ·
Maintainer thường phản hồi trong vòng 1 ngày