I am facing an issue with integrating my Electron app, written mainly in JavaScript, with an Express server project built in TypeScript. When I attempt to create a child process of the TypeScript project within my electron.js file, I encounter TypeScript errors stating that my server.js does not recognize the .ts file extension it is trying to import. The actual files exist, but they are not being handled correctly.
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"
==== Electron App ===
Here is the snippet from my package.json in the Electron app:
"scripts": {
"build": "react-app-rewired build",
"start": "react-app-rewired start",
"electron": "electron ."
}
tsconfig.json
{
"compilerOptions": {
// Compiler options here
},
"include": ["src", "expressproject/src"]
}
This is how I'm attempting to run the Express project in my electron.js file:
// electron.js
const { spawn } = require("child_process");
// Code to start express server
const expressServerProcess = spawn("node", [pathToExpressServerJS]); // D:/expressproject/src/server.js
function createWindow() {
...
}
==== Express Project ====
Snippet from the package.json in the TypeScript Express project:
"scripts": {
"build": "tsc -p tsconfig.json",
"start": "npm run build && node --loader ts-node/esm --experimental-specifier-resolution=node server.js",
}
tsconfig.json
{
"extends": "ts-node/node16/tsconfig.json",
// Compiler and transpile options here
}
It seems like the TypeScript code is not being properly transpiled to JavaScript. How can I ensure that the transpilation process is executed correctly?