Closed fasihrana closed 5 years ago
Hi @fasihrana,
ClearScript currently doesn't support ES6 modules. We're evaluating adding support for both ES6 and Node.js-style modules in an upcoming release.
Thanks!
ClearScript 5.6 includes basic support for modules.
ClearScript 5.6 includes basic support for modules.
Can you please show an example how to enable import/export in ClearScript? We try to use modules but allways return one error "SyntaxError: Unexpected identifier" in code
import ScriptClass1 from "ScriptClass1.js";
Привет @Ariohor ,
Посмотрите на метод испытаний здесь .
Удачи!
Thank you very much!
I have a follow up question on this, What's the best way to import modules installed using NPM in visual studio? I have a package.json file that installs the dependencies in a node_modules folder.
Hi @karimi,
You can use DocumentSettings.SearchPath
to specify your module locations.
Please let us know if you need additional information.
Good luck!
Thanks, that's what I was looking for. I also had to have a build event that copies the node_modules to my build folder.
I have a question, I have this C# code
public JsonResult CreatePPT(string JSONToPass, string VisualInfo) {
var jsonObject = JsonConvert.DeserializeObject<JSONModel>(JSONToPass);
using (var engine = new V8ScriptEngine())
{
// Load the JavaScript script from a file
var script = System.IO.File.ReadAllText("C:\\Users\\PrathmeshHanamantPaw\\Downloads\\GlobalReportFramework\\GlobalReportFramework - Copy\\GlobalReportFramework\\createPPT.js");
// Set the values of connectionString, containerName, and outputPath in the JavaScript context
var connectionString = Common.Constants.blobConnectionString;
var containerName = jsonObject.Guid;
var outputPath = Common.Constants.sessionFolder + Common.Constants.updatedPPTFileNamePath + jsonObject.Guid;
engine.Script.connectionString = connectionString;
engine.Script.containerName = containerName;
engine.Script.outputPath = outputPath;
// Execute the JavaScript code
engine.Execute(script);
engine.Script.createPresentation();
}
return null;
}
the JS script doesn't run returns an Error : "require is not defined"
NOTE: I have used require to use installed npm packages
Hi @pp2110,
The require
function is available only within CommonJS modules. You can use ClearScript to execute a CommonJS module as follows:
var info = new DocumentInfo { Category = ModuleCategory.CommonJS };
engine.Execute(info, script);
Note however that ClearScript provides a bare JavaScript environment containing only the JavaScript built-ins It does not implement the Web or Node.js APIs.
Is there a way to enable "import <module>.js;" statements in a V8 Runtime?
I couldn't find any examples and makes me think I'd have to parse the script file myself first to enable this.
As on StackOverflow.