pucelle / vscode-run-on-save

Run configured shell commands when a file is saved in vscode, and output configured messages on status bar.
https://marketplace.visualstudio.com/items?itemName=pucelle.run-on-save
MIT License
50 stars 11 forks source link

`npm: command not found` #37

Closed marcosh closed 6 months ago

marcosh commented 7 months ago

I'm trying to set up Run on save on one vscode project.

I'd like it to run a npm script, so I configured it like

{
  "runOnSave.statusMessageTimeout": 3000,
  "runOnSave.commands": [
    {
      "match": ".*\\.purs$",
      "command": "npm run format-single -- ${fileRelative}",
      "runIn": "backend",
      "runningStatusMessage": "Formatting ${fileBasename}",
      "finishStatusMessage": "${fileBasename} formatted"
    }
  ]
}

When I save a .purs file, the command is correctly triggered, but it produces a

Running "npm run format-single -- src/Components/PaymentRegion.purs"
/bin/sh: line 1: npm: command not found

error message.

npm is correctly installed on my system, and, in fact, if I run the same trigger using runIn: "terminal", it works correctly.

What should I do to make npm visible to run-on-save?

pucelle commented 6 months ago

I think this is not the issue of this plugin. I did some search, and this is the closest answer I found - https://stackoverflow.com/questions/31472755/sudo-npm-command-not-found.

marcosh commented 6 months ago

Thanks for the hint. I solved it modifying my configuration to

{
  "runOnSave.statusMessageTimeout": 3000,
  "runOnSave.commands": [
    {
      "match": ".*\\.purs$",
      "command": "export PATH=/home/marcosh/.nvm/versions/node/v16.20.0/bin:$PATH && echo $PATH && npm run format-single -- ${fileRelative}",
      "runIn": "backend",
      "runningStatusMessage": "Formatting ${fileBasename}",
      "finishStatusMessage": "${fileBasename} formatted"
    }
  ]
}