Skip to content
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

Sharp in an Electron Forked Process #1621

Closed
JakeRadMSFT opened this issue Mar 22, 2019 · 5 comments
Closed

Sharp in an Electron Forked Process #1621

JakeRadMSFT opened this issue Mar 22, 2019 · 5 comments

Comments

@JakeRadMSFT
Copy link

JakeRadMSFT commented Mar 22, 2019

Sharp doesn't work in an electron forked process.

Caused by:

mapbox/node-pre-gyp#278

That used to be blocked by this:
electron/electron#9058

@lovell
Copy link
Owner

lovell commented Mar 23, 2019

Hi, sharp uses prebuild and prebuild-install rather than node-pre-gyp but the problem may be similar.

I've had a quick scan of the linked issues. Is the main cause of the problem that the runtime has been incorrectly determined to be "node" rather than "electron"? If so, this can be passed in at install-time via a flag:

npm install --runtime=electron

If this doesn't help, please can you provide a repo with a minimal reproduction of the problem.

@JakeRadMSFT
Copy link
Author

Sorry accidentally closed. I'll try to create a minimal reproduction of the problem.

@BiancoA
Copy link
Contributor

BiancoA commented Apr 8, 2019

I use Sharp in a forked process in my electron app.I do something like this:

const {fork} = require('child_process');

  var cwd, scriptPath;
  const isDevelopment = process.env.NODE_ENV !== 'production'
  if (isDevelopment) {
    cwd = __dirname;
    scriptPath = './usesharp.js';
  } else {
    // __dirname points to app.asar in production, which is a virtual directory
    // virtual directory can be read, but not used as cwd. Workaround: use __dirname/../ as cwd for child process
    cwd = path.join(__dirname, '..');
    // reading from app.asar is ok.
    // usesharp.js is living in scripts in production, fork() needs a unbundled, single file
    scriptPath = 'app.asar/scripts/usesharp.js';
  }

this.childProcess = fork(scriptPath, [], {
    cwd: cwd,
    silent: true
});

@lovell
Copy link
Owner

lovell commented May 2, 2019

It looks like the upstream electron/electron#16450 fixes this, which will be in Electron 6.

@mubaidr
Copy link

mubaidr commented Aug 31, 2019

I am also using Sharp in fork processes it works just fine. I did not have to do anything special to be able to use it inside forks.

@lovell lovell closed this as completed Sep 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants