Taritsyn / JavaScriptEngineSwitcher

JavaScript Engine Switcher determines unified interface for access to the basic features of popular JavaScript engines. This library allows you to quickly and easily switch to using of another JavaScript engine.
Apache License 2.0
439 stars 49 forks source link

Jering.Javascript.NodeJS JsCompilationException on spawn identifier #105

Closed soroshsabz closed 2 years ago

soroshsabz commented 2 years ago

ITNOA

Hi

I have a GitHub project https://github.com/soroshsabz/visualstudio-ansible and in Ansible.VisualStudio.LanguagerServer vs project, I have SpawnServer.js file that content like below

const { spawn } = require("child_process");

spawn("npx", ["ansible-language-server"].concat(process.argv[2]), { stdio: 'inherit' });

When I want to run this script from C# code I got JsCompilationException withe below details

Exception thrown: 'JavaScriptEngineSwitcher.Core.JsCompilationException' in JavaScriptEngineSwitcher.Node.dll
An unhandled exception of type 'JavaScriptEngineSwitcher.Core.JsCompilationException' occurred in JavaScriptEngineSwitcher.Node.dll
SyntaxError: Identifier 'spawn' has already been declared
   at SpawnServer.js:1:1 -> // ITNOA

My loading code like below

using JavaScriptEngineSwitcher.Core;
using JavaScriptEngineSwitcher.Jurassic;
using JavaScriptEngineSwitcher.Node;
using System;

namespace Ansible.VisualStudio.LanguageServer
{
    public class Loader
    {
        public Loader()
        {
            IJsEngine engine = new NodeJsEngine();
            engine.ExecuteFile("SpawnServer.js");
        }
    }
}

Where is my wrong?

if you want to see my code in GitHub you can see language-server branch

I create same Question in SO

thanks

soroshsabz commented 2 years ago

related to https://github.com/JeringTech/Javascript.NodeJS/issues/139 I close this issue