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

child_process.spawn not working on Windows #1180

Closed
feickertm opened this issue Nov 24, 2021 · 1 comment
Closed

child_process.spawn not working on Windows #1180

feickertm opened this issue Nov 24, 2021 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@feickertm
Copy link

While I was trying to run caliper bind on windows. I was getting the error that it is not able to spawn the npm child process.

Context

I am not sure if this is only a problem with my special setup, but it seems Windows has some problems with spawning a child process. I am no JavaScript expert, but as I understand it child_process.spawn ignores the PATHEXT on Windows and therefore won't find the npm.cmd.

Is anyone facing the same issue on Windows or can reproduce this?

Expected Behavior

npx caliper bind --caliper-bind-sut fabric:2.2
runs without error

Actual Behavior

executing npx caliper bind --caliper-bind-sut fabric:2.2 on Windows gives the following error

$ npx caliper bind --caliper-bind-sut fabric:2.2
2021.11.24-13:43:42.959 info  [caliper] [bind]  Binding for fabric@2.2. This might take some time...
2021.11.24-13:43:42.960 info  [caliper] [bind]  Calling npm with: install fabric-network@2.2.3 fabric-ca-client@2.2.3
node:events:368
      throw er; // Unhandled 'error' event
      ^

Error: spawn npm ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19)
    at onErrorNT (node:internal/child_process:477:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (node:internal/child_process:288:12)
    at onErrorNT (node:internal/child_process:477:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn npm',
  path: 'npm',
  spawnargs: [ 'install', 'fabric-network@2.2.3', 'fabric-ca-client@2.2.3' ]
}

I have tried it using different node and npm versions, so I guess it is not a problem with my node or npm.

Possible Fix

I was able to fix this problem, by changing const {exec, spawn} = require('child_process'); to

const exec = require('child_process');
const spawn = require('cross-spawn');

In caliper-utils.js
This is replacing nodes own spawn with a cross plattform solution.

Steps to Reproduce

  1. Install caliper node package on Windows
  2. run npx caliper bind --caliper-bind-sut fabric:2.2

Your Environment

  • Version used: Caliper v0.4.2, Fabric v2.2
  • Environment name and version: node 14.13.1 with npm 6.4.1 and node 16.13.0 with 8.1.0
  • Operating System and version: Windows 10
@davidkel davidkel self-assigned this Jan 12, 2022
@davidkel
Copy link
Contributor

This has actually been fixed already by #1127
but unfortunately not available in a release yet. Closing

@davidkel davidkel added this to the v0.5.0 milestone Mar 2, 2022
@davidkel davidkel added the bug Something isn't working label Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants