Jering.Javascript.NodeJS.InvocationException - resolvedPath.replaceAll is not a function
Hi, I try to use the API for InvokeFromFileAsync but I recieve the following exception:
Message = "resolvedPath.replaceAll is not a function\nTypeError: resolvedPath.replaceAll is not a function\n at IncomingMessage.
It occurs for my .js file (which using 3rd party js library) so I tested the example from readme, but same error:
start.js
module.exports = (callback, message) => callback(null, { resultMessage: message });
C# code is
var services = new ServiceCollection();
services.AddNodeJS();
ServiceProvider serviceProvider = services.BuildServiceProvider();
INodeJSService nodeJSService = serviceProvider.GetRequiredService<INodeJSService>();
string scriptPath = @"C:\Users\user\Desktop\enc\start.js";
var result = await nodeJSService.InvokeFromFileAsync<Result>(scriptPath, args: new[] { "success" });
The exception thrown on the calling to InvokeFromFileAsync
The original JS code was
var package = require('some-installed-package');
function test(param){
return package.someMethod(param)
}
module.exports = {
test: test
}
var result = await nodeJSService.InvokeFromFileAsync<Result>(scriptPath, "test", args: new[] { "success" });
Not sure what I've missed.
What NodeJS version are you using? For me I had the same issue and turned out I was using NodeJS v14 on my server, after upgrading it to NodeJS v20 everything worked as usual.
NodeJS version 21.5.0
It's a long shot but you could try downgrading to Node 20 which is the current LTS and see if it works.