I’m trying out a .NET solution with Jurassic to call a javascript file in the root folder that will do a fetch(url). Unfortunately, I get a Jurassic.JavaScriptException: 'SyntaxError: Unexpected token 'import' in expression.'
error while testing due to the import fetch from "node-fetch";
line I need to use the fetch command. While I’m able to do this in a javascript solution in Visual Studio 2022 with no problems, when I try to do it in a C# solution, I have this error, I assume it’s because the dependencies for node and node-fetch I installed through npm are handled differently, is there a way to resolve this?
The .cs code:
using Jurassic;
var engine = new Jurassic.ScriptEngine();
engine.ExecuteFile(@"script.js");
engine.Execute("fetch('myurl')");
The app.js script:
import fetch from "node-fetch";
The C# solution
The package.json is as follows:
{
"name": "JurassicTest",
"version": "1.0.0",
"type": "module",
"dependencies": {
"node": "^18.20.4",
"node-fetch": "^3.3.2"
}
}
Is there a way I can compile the javascript solution that’s working correctly separately and then call it through the .NET/Jurassic? I tried it but I couldn’t get it to work.
I also tested Jint but it has the same effect.
Thanks for the help.
Miguel Teixeira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1