Skip to content

Problems importing native modules (for Electron app) #3482

Closed
@kevinbuhmann

Description

@kevinbuhmann

OS?

Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)

Windows 10 x64

Versions.

Please run ng --version. If there's nothing outputted, please run in a Terminal: node --version and paste the result here:

>ng --version
angular-cli: 1.0.0-beta.22-1
node: 6.9.1
os: win32 x64

Repro steps.

Was this an app that wasn't created using the CLI? What change did you do on your code? etc.

I am building an electron app, but I am having trouble importing the "child_process" core module. Each of the follow result in a compile time "can't resolve 'child_process'" error (see error 1 below).

  • import * as childProcess from 'child_process';
  • import { exec } from 'child_process';
  • const exec: any = require('child_process').exec;

However, the following don't result in a compile time error, but it results in an uncaught type error at run time.

  • import { ipcRenderer, remote } from 'electron'; (see error 2 below)
  • import * as fs from 'fs'; (see error 3 below)

This workaround/hack works but 1) uses eval and 2) doesn't have type system support:

  • const exec: any = eval("require('child_process').exec");
  • const fs: any = eval("require('fs')");
  • const ipcRenderer: any = eval('require(\'electron\').ipcRenderer');

The log given by the failure.

Normally this include a stack trace and some more information.

  1. Compile time error when importing "child_process."
ERROR in ./src/app/shared/services/shell.service.ts
Module not found: Error: Can't resolve 'child_process' in 'C:\path\to\app\shared\services'
 @ ./src/app/shared/services/some.service.ts 10:0-46
 @ ./src/app/shared/shared.module.ts
 @ ./src/app/app.module.ts
 @ ./src/app/index.ts
 @ ./src/main.ts
 @ multi main
  1. Run time error when importing "electron."
"Uncaught TypeError: fs.readFileSync is not a function"
  1. When importing "fs"
Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_0_fs__.lstatSync is not a function

Mention any other details that might be useful.


Thanks! We'll be in touch soon.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions