0

The Compress-Archive command doesn't work for chain npm commands,

For Ex:

> npm run some_command && Compress-Archive src target

  • Does this answer your question? [Can I get && to work in Powershell?](https://stackoverflow.com/questions/563600/can-i-get-to-work-in-powershell) – Tomalak Jan 27 '20 at 11:15
  • I don't have a problem with `&&` ,It's already working . The problem is with `Compress-Archive` – waseem isaac Jan 27 '20 at 11:19
  • 2
    There is no `&&` in Powershell. If the `&&` is working then you are not using Powershell. (And then it should not be a surprise that Powershell cmdlets are not working) – Tomalak Jan 27 '20 at 11:25
  • If you run `npm config get script-shell` from Powershell it typically returns the path to `cmd.exe` as that's the default shell that npm utilizes on Windows regardless of the CLI tool you're using, i.e. _Command Prompt_, _Powershell_, etc. That's why the `&&` operator is working. As @Tomalak said you're effectively not using Powershell. You need to utilize the `npm config set script-shell ...` command to config npm to use PowerShell as explained in [this answer](https://stackoverflow.com/questions/55300421/how-can-i-make-npm-projects-with-bash-shell-commands-work-on-windows?#answer-55303370) – RobC Jan 27 '20 at 11:39
  • It works with Powershell within an Angular project (package.json file scripts). This an image from my Poweshell now https://i.stack.imgur.com/2tz7o.png @Tomalak – waseem isaac Jan 27 '20 at 11:42
  • Yes , U are right @RobC – waseem isaac Jan 27 '20 at 11:44
  • So what are the Powershell specific command(s) (such as `Compress-Archive`) in that screen screenshot? I can't see any. – RobC Jan 27 '20 at 11:45
  • Here https://i.stack.imgur.com/NqkPS.png @RobC – waseem isaac Jan 27 '20 at 11:49
  • @waseemisaac - That _"Compress-Archive: command not found "_ error seems to indicate that the shell is set to bash. Have you actually tried utilizing the `npm config set script-shell` command and setting it to `pwsh` as per my earlier comment? (Run `get-command powershell.exe` to get the path). Personally, if I wanted my package to work cross-platform I'd avoid using shell specific commands in npm scripts. Consider using a node.js tool such as [node-acrchiver](https://github.com/archiverjs/node-archiver) to create a compressed archive. You can then invoke your node.js script via an npm script. – RobC Jan 27 '20 at 12:07
  • @RobC Thanks , I Used node-archiver :) – waseem isaac Jan 27 '20 at 12:59

0 Answers0