Skip to content

Problems importing native modules (for Electron app) #3482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kevinbuhmann opened this issue Dec 8, 2016 · 2 comments
Closed

Problems importing native modules (for Electron app) #3482

kevinbuhmann opened this issue Dec 8, 2016 · 2 comments

Comments

@kevinbuhmann
Copy link
Contributor

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.

@hansl
Copy link
Contributor

hansl commented Dec 8, 2016

We will not support universal or electron officially until addon themselves are supported.

You're better off using a seed or implementing your own webpack config for Electron builds. Sorry.

@hansl hansl closed this as completed Dec 8, 2016
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants