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

Command failed with exit code 1: npm #1

Closed
parloti opened this issue Apr 12, 2022 · 5 comments
Closed

Command failed with exit code 1: npm #1

parloti opened this issue Apr 12, 2022 · 5 comments

Comments

@parloti
Copy link

parloti commented Apr 12, 2022

npx git-pull-run -p "package-lock.json" -c "npm install"

this command throws the following error

git-pull-run Running command 'npm' for change 'package-lock.json' in directory C:\...\...\...
error Error: Command failed with exit code 1: npm

the command being executed is npm and not npm install.

@zirkelc
Copy link
Owner

zirkelc commented Apr 12, 2022

Hi @parloti!

That issue could be related to Windows and the working directory.

Could you run the command with --debug flag and post the entire output here?
Do you run it manually or as Husky hook?

@parloti
Copy link
Author

parloti commented Apr 24, 2022

I ran it as a Husky hook and manually on windows, the result is the same.

Perhaps an option, as defined here, does not accept a multiword argument.

Modifying this line to const cmdProcess = execaCommand(cmd.replace(':',' '), { cwd });.
And running this npx git-pull-run -p \"package-lock.json\" -c \"npm:install\" --debug worked for me.

This is the original output, with no code change.

> npx git-pull-run -p "package-lock.json" -c "npm install" --debug
  git-pull-run Started [email protected] +0ms
  git-pull-run:getGitDirectory Get git directory +0ms
  git-pull-run:runGit Running git 'git rev-parse --show-toplevel' +0ms
  git-pull-run:runGit Git command executed with exit code: 0 +125ms
  git-pull-run:getGitDirectory Git directory: C:/Users/*** +127ms
  git-pull-run:getChanges Get changed files +0ms
  git-pull-run:runGit Running git 'git diff --name-only HEAD@{1} HEAD' +2ms
***
  git-pull-run:runGit Git command executed with exit code: 0 +172ms
  git-pull-run:getChanges Changed files: [***] +174ms
  git-pull-run:getChanges Match files with pattern 'package-lock.json': [ 'package-lock.json' ] +21ms
  git-pull-run Found 1 change for pattern 'package-lock.json' +0ms
  git-pull-run:getAbsolutePath Absolute path resolved: C:\Users\*** +0ms
  git-pull-run Running command 'npm' for change 'package-lock.json' in directory C:\Users\*** +2ms
  git-pull-run:runCommand Running command 'npm' in directory 'C:\Users\***' +0ms

Usage: npm <command>

where <command> is one of: ***

[email protected] C:\Program Files\nodejs\node_modules\npm
  git-pull-run:runCommand Command failed with exit code: 1 +21s
error Error: Command failed with exit code 1: npm
Debugger attached.
Waiting for the debugger to disconnect...

[email protected] C:\Program Files\nodejs\node_modules\npm
    at runCommand (file:///C:/Users/***/node_modules/git-pull-run/dist/runCommand.js:17:15)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async gitPullRun (file:///C:/Users/***/node_modules/git-pull-run/dist/index.js:25:32)
  git-pull-run Finished [email protected] +2m
Waiting for the debugger to disconnect...
Waiting for the debugger to disconnect...
/c/Program Files/nodejs/npm: line 37:   447 Segmentation fault      "$NODE_EXE" "$NPM_CLI_JS" "$@"

@zirkelc
Copy link
Owner

zirkelc commented Apr 25, 2022

@parloti thank you for your investigation so far.

This seems to be a known problem of Node on Windows, see nodejs/node#7367

I'm using the execa package to execute the commands and it suggests to escape white spaces in the command with backslashes.

Same as execa() except both file and arguments are specified in a single command string. For example, execa('echo', ['unicorns']) is the same as execaCommand('echo unicorns').
If the file or an argument contains spaces, they must be escaped with backslashes.

I don't have access to a Windows machine at the moment, so I couldn't verify yet. Could you please give it a try:
npx git-pull-run -p \"package-lock.json\" -c \"npm\ install\" --debug

@parloti
Copy link
Author

parloti commented Apr 25, 2022

npx git-pull-run -p \"package-lock.json\" -c \"npm\ install\"

That worked like a charm.

@zirkelc
Copy link
Owner

zirkelc commented Apr 26, 2022

Thank you, I'm going to add it to the README.

@zirkelc zirkelc closed this as completed Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants