Require nodejs "child_process" with TypeScript, SystemJS and Electron
Ok, after some research #L138 I have found the solution
You can use import
as before
import * as child from 'child_process';var foo: child.ChildProcess = child.exec('foo.sh');console.log(typeof foo.on);
But you should configure SystemJS
to map the module to NodeJS
.
System.config({ map: { 'child_process': '@node/child_process' }});
That's it!
If the error message is 'Cannot find module 'child_process' or its corresponding type declarations' the answer is 'npm install @types/watch'
For me it worked with the callback to display the results.
import * as child from 'child_process'; var foo: child.ChildProcess = child.exec('dir', (error: string, stdout: string, stderr: string) => { console.log(stdout); });
I didn't add any mappings in SystemJS as I dont have any such configuration in the node application