visual-studionpmvisual-studio-codepackage.jsontask-runner-explorer

How to run npm audit using the Task Runner Explorer?


I guess it is trivial, but I did not manage to figure out how to adjust my package.json so that I could run npm audit using the Task Runner Explorer by Mad Kirstensen within Visual Studio (Professional 2017).

My package.json starts with

{
  "version": "1.4.6",
  "name": "myProject.UI",
  "private": true,
  "scripts": {
    "npm audit": "npm audit",
    "webpack": "webpack -w --mode='development' --colors --config webpack.config.js",
  }, ...

The 2nd entry in the section scripts works fine, the 1st one does not, since the Task Runner Explorer always adds a cmd.exe /c npm run as prefix to all scripts defined in package.json. This is what also what the error message says:

cmd.exe /c npm run npm audit --color=always
npm ERR! missing script: npm

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Me\AppData\Roaming\npm-cache\_logs\2020-04-01T01_23_45_6789Z-debug.log

How do I have to modify my package.json to be able to start a npm audit using the Task Runner Explorer?

Related


Solution

  • I'm afraid that in npm all script entries have a single string by design.

    After all, package.json is just a json file and a such the "key" in the key/value pairs need to be a single valid string.

    E.g. npm_audit instead of npm audit:

    {
        "version": "1.4.6",
        "name":    "myProject.UI",
        "private": true,
        "scripts": {
            "npm_audit": "npm audit",
            "webpack":   "webpack -w --mode='development' --config webpack.config.js",
    }, ...