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

[Bug] External dependencies from node_modules not being resolved

Open openbullet opened this issue 1 year ago • 2 comments

Hello.

First of all, thank you for your amazing work. I'm using version 7.0.0 of this library in my own .NET 8 library, and I've run into an issue. I have a node_modules folder with axios installed inside it. I am running the program from the same folder that contains the node_modules folder, and I'm using StaticNodeJSService.InvokeFromStringAsync<T> to run this script:

module.exports = async () => {
    const axios = require('axios');
    await axios.get('https://example.com');
    console.log("OK");
};

I always get axios is not defined. I even tried to Configure<NodeJSProcessOptions> and set the ProjectPath or the NODE_PATH environment variable, but it didn't help.

I'm using node v20.11.1 and npm 10.2.4

openbullet avatar Jul 15 '24 21:07 openbullet

Hi I have no issue with that. But I use InvokeFromFileAsync instead of InvokeFromStringAsync: _nodeJSService.InvokeFromFileAsync<string>("getTimeZone.js", "getTimeZone", args: new[] { latitude.ToString(), longitude.ToString() });

and my folder: image getTimeZone.js: image

And my path setting: builder.Services.AddNodeJS(); string path = Path.Combine(builder.Configuration.GetValue<string>(WebHostDefaults.ContentRootKey), "nodejs"); builder.Services.Configure<NodeJSProcessOptions>(options => options.ProjectPath = path);

And it's works Hope it's help

chetvergok avatar Aug 06 '24 08:08 chetvergok

Hi I have no issue with that. But I use InvokeFromFileAsync instead of InvokeFromStringAsync:

Hello.

This is exactly the issue I'm facing. It works fine with InvokeFromFileAsync but my project requires the use of InvokeFromStringAsync.

openbullet avatar Aug 07 '24 08:08 openbullet