Javascript.NodeJS icon indicating copy to clipboard operation
Javascript.NodeJS copied to clipboard

Jering.Javascript.NodeJS.InvocationException - resolvedPath.replaceAll is not a function

Open Orh1989 opened this issue 2 years ago • 3 comments

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. (file:///C:/Users/user/source/repos/ConsoleApp1/ConsoleApp2/bin/Debug/net6.0/[eval1]:178:58)\n at IncomingMessage.emit (events.js:412:35)\n at endReadableNT (internal/streams/readable.js:1334:12)\n at processTicksAndRejections (internal/process/task_queues.js:82:21)"

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.

Orh1989 avatar Dec 20 '23 11:12 Orh1989

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.

KhoaNam225 avatar Jan 02 '24 03:01 KhoaNam225

NodeJS version 21.5.0

Orh1989 avatar Jan 02 '24 07:01 Orh1989

It's a long shot but you could try downgrading to Node 20 which is the current LTS and see if it works.

KhoaNam225 avatar Jan 02 '24 07:01 KhoaNam225