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

[BUG](arborist) node-gyp doesn't work from within Electron #4291

Closed
hrueger opened this issue Feb 2, 2021 · 2 comments
Closed

[BUG](arborist) node-gyp doesn't work from within Electron #4291

hrueger opened this issue Feb 2, 2021 · 2 comments
Labels
ws:arborist Related to the arborist workspace

Comments

@hrueger
Copy link

hrueger commented Feb 2, 2021

What / Why

Hi,
I have an Electron app in which I am using arborist to install npm packages into a folder at runtime. Those packages are then required and used. When I install a package which requires native addon modules to be rebuilt using node-gyp, I encounter the following error:

  <rejected> Error: command failed
      at ChildProcess.<anonymous> (C:\Users\Hannes\AppData\Local\Programs\glue\resources\app.asar\node_modules\@npmcli\promise-spawn\index.js:64:27)
      at ChildProcess.emit (events.js:315:20)
      at maybeClose (internal/child_process.js:1021:16)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5) {
    cmd: 'C:\\WINDOWS\\system32\\cmd.exe',
    args: [
      '/d',
      '/s',
      '/c',
      'prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild'
    ],
    code: 1,
    signal: null,
    stdout: '',
    stderr: 'Der Befehl "node-gyp" ist entweder falsch geschrieben oder\r\n' +
      'konnte nicht gefunden werden.\r\n',
    event: 'install',
    script: 'prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild',
    pkgid: '@serialport/[email protected]',
    path: 'C:\\Users\\Hannes\\AppData\\Roaming\\glue\\data\\features\\node_modules\\@serialport\\bindings'
  }
} reason: Error: command failed
    at ChildProcess.<anonymous> (C:\Users\Hannes\AppData\Local\Programs\glue\resources\app.asar\node_modules\@npmcli\promise-spawn\index.js:64:27)
    at ChildProcess.emit (events.js:315:20)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5) {
  cmd: 'C:\\WINDOWS\\system32\\cmd.exe',
  args: [
    '/d',
    '/s',
    '/c',
    'prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild'
  ],
  code: 1,
  signal: null,
  stdout: '',
  stderr: 'Der Befehl "node-gyp" ist entweder falsch geschrieben oder\r\n' +
    'konnte nicht gefunden werden.\r\n',
  event: 'install',
  script: 'prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild',
  pkgid: '@serialport/[email protected]',
  path: 'C:\\Users\\Hannes\\AppData\\Roaming\\glue\\data\\features\\node_modules\\@serialport\\bindings'
}

The german (sorry for that, but my windows is set to German) translates to The command "node-gyp" is either misspelled or could not be found.
All of this happens in the Electron Main process. The end-user will not have NodeJS nor node-gyp installed.
So I ship it with my electron app. But how can I tell arborist to use node-gyp from that path?

When

I install a npm package requiring node-gyp rebuilds.

Where

In an Electron main process

  • n/a

How

?

Current Behavior

See above

Steps to Reproduce

  • n/a

Expected Behavior

It should rebuild the dependencies.

Who

  • n/a

References

@fritzy fritzy transferred this issue from npm/arborist Jan 20, 2022
@fritzy fritzy added Needs Triage needs review for next steps ws:arborist Related to the arborist workspace labels Jan 20, 2022
@fritzy fritzy changed the title [BUG] node-gyp doesn't work from within Electron [BUG](arborist) node-gyp doesn't work from within Electron Jan 20, 2022
@ruyadorno ruyadorno removed the Needs Triage needs review for next steps label Mar 1, 2022
@ruyadorno
Copy link
Contributor

Hi @hrueger thanks for sharing that, it's definitely a super interesting usage of arborist and one I'd love to try to hack with a bit more myself 😄

With that in mind, one possible way I could see to try and work around this issue would be to maybe just a setup step in your app in which you reify node-gyp (and possibly any similar potential system dependency) either in that path as a dev dependency (might be not ideal since it's going to modify package.json, lock file, etc) or in the global folder (equivalent of npm i -g node-gyp) so that you can ensure it's installed and available by the time you try to reify something else.

@mmomtchev
Copy link

Because of two require.resolve statements - including the node-gyp one and an additional one coming from @sigstore/tuf for seeds.json, arborist currently cannot be (easily) bundled for server-less environments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ws:arborist Related to the arborist workspace
Projects
None yet
Development

No branches or pull requests

4 participants