0
import { exec } from "child_process";

I am having a problem with using child_process in Angular 15. I always get this error:

ERROR in src/app/gerfactory/gerfactory.component.ts:6:22 - error TS2307: Cannot find module 'child_process' or its corresponding type declarations.

I installed it by typing npm i child_process, but whenever I try to call it in my Angular application, I get the error message above.

This is the function I wrote that needs to use {exec} from "child_process":

  async runMiddleWare(path: string){
    exec(path, (error, stdout, stderr) =>{
      if (error) {
        console.error(`Error executing software: ${error.message}`);
        return;
      }
      if (stderr) {
        console.error(`Software error: ${stderr}`);
        return;
      }
      console.log(`Software output: ${stdout}`);
    });
  }

UPDATE: Just now I discovered child_process was removed from the npm (see here on npmjs.com). However, I need my front-end application to be able to call a software in my local computer, since this is how the client wants it to work (go figure). Does anyone know how to do it?

  • 2
    I think `child_process` is only available in a node application context, not in a browser based angular application. – Jake Smith Jun 13 '23 at 20:38
  • What kind of commands should be executed in the desktop from web browser? – JRichardsz Jun 13 '23 at 20:43
  • I saw some people using it in Angular, and I basically copied the code and modified a little. However it's probably been over a year last I saw it. – Gabriel Falcão Jun 13 '23 at 20:46
  • It has to initiate another software locally installed. This software has to execute a few tests on devices connected to the computer. They requested it because they do not want testers to manually open the tester software. – Gabriel Falcão Jun 13 '23 at 20:48
  • You might want to look into integrating something like Electron with Angular. Electron let's you create a desktop application, running in a node context, where child_process will be available to you on the electron side. Then Angular can run in the renderer process as the frontend of the desktop app. But due to security reasons, the browser doesn't really allow access to the local file system on the machine you are running the browser app on. The other option would be to create a minimal web api for angular to "talk" to that DOES have access to the file system. GL! – Jake Smith Jun 13 '23 at 20:55

0 Answers0