Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Orh1989 opened this issue Dec 20, 2023 · 3 comments

Comments

@Orh1989
Copy link

Orh1989 commented Dec 20, 2023

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.

@KhoaNam225
Copy link

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.

@Orh1989
Copy link
Author

Orh1989 commented Jan 2, 2024

NodeJS version 21.5.0

@KhoaNam225
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants