I want to run some TypeScript Code written in ES2020 on Server Side. Currently i have running a ASP.NET Core Application so the idea was to run js via Jering.Javascript.NodeJS and nodejs.
So started with a basic example.
var test = await StaticNodeJSService.InvokeFromFileAsync<string>("Scripts/server/modules/hello.ts", args: new object[] { });
hello.ts
module.exports = (callback, x, y) => { // Module must export a function that takes a callback as its first parameter
var result = "test"; // Your javascript logic
callback(null /* If an error occurred, provide an error object or message */, result); // Call the callback when you're done.
}
Works...added some import statemant...
hello.ts
import someFunction from "./some.func";
module.exports = (callback, x, y) => { // Module must export a function that takes a callback as its first parameter
var result = "test"; // Your javascript logic
callback(null /* If an error occurred, provide an error object or message */, result); // Call the callback when you're done.
}
--> "Cannot use import statement outside a module"
Nodejs version v16.13.2 and in package.json there is already set
"type": "module"
changing to require
hello.ts
const someFunction = require("./some.func")
module.exports = (callback, x, y) => { // Module must export a function that takes a callback as its first parameter
var result = "test"; // Your javascript logic
callback(null /* If an error occurred, provide an error object or message */, result); // Call the callback when you're done.
}
results in "InvocationException: require() of ES Module ... from ... not supported. Instead change the require of some.func.js in ... to a dynamic import() which is available in all CommonJS modules"
So kind of infinity loop.
By looking here it seems to be possible but how do i get this running?