watchify error - npm ERR! missing script: watch

15.4k Views Asked by At

I am trying to figure out how to use this library called simple-peer, so I have setup a test project. It has the following dir structure:

enter image description here

and this is the content of my package.json file:

{
  "author": "Latheesan Kanesamoorthy",
  "name": "simple-peer-test",
  "version": "1.0.0",
  "description": "A simple video chat app using simple-peer using WebRTC.",
  "main": "main.js",
  "scripts": {
    "start": "nodemon ./src/server.js",
    "watch": "npx watchify ./src/main.js -o ./public/bundle.js"
  },
  "dependencies": {
    "express": "^4.17.1",
    "simple-peer": "^9.4.0",
    "socket.io": "^2.2.0"
  },
  "devDependencies": {
    "nodemon": "^1.19.1",
    "watchify": "^3.11.1"
  }
}

When I run this command: npm run watch, I am getting this error:

npm ERR! missing script: watch

Here's my debug.log:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'watch' ]
2 info using [email protected]
3 info using [email protected]
4 verbose stack Error: missing script: watch
4 verbose stack     at run (C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:155:19)
4 verbose stack     at C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:63:5
4 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:115:5
4 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:418:5
4 verbose stack     at checkBinReferences_ (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:373:45)
4 verbose stack     at final (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:416:3)
4 verbose stack     at then (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:160:5)
4 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:364:12
4 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:90:16
4 verbose stack     at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)
5 verbose cwd C:\Users\Latheesan\Desktop\simple-peer-test
6 verbose Windows_NT 10.0.17763
7 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "watch"
8 verbose node v10.16.0
9 verbose npm  v6.9.0
10 error missing script: watch
11 verbose exit [ 1, true ]

Any idea what might be wrong here?

I am on Windows 10 Pro (x86_64) with NodeJS v10.16.0 and NPM v6.9.0.

3

There are 3 best solutions below

0
Pat On

You have to add npm-watch to the packages.json

"scripts": {
    "watch": "npm-watch",
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  }

Also add

"watch": {
    "build": {
      "patterns": [
        "src"
      ],
      "extensions": "js,jsx"
    }
  }
0
Tehreem Amjad On

if npm run watch generates an error like:

npm ERR! Missing script: "watch"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR!   npm run

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\LENOVO\AppData\Local\npm-cache\_logs\2023-03-06T06_35_07_482Z-debug-0.log

So just simply run this following command:

npm install npm-watch
0
heena kaushar On

if npm run watch generates an error like:

npm ERR! Missing script: "watch"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR!   npm run

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\LENOVO\AppData\Local\npm-cache\_logs\2023-03-06T06_35_07_482Z-debug-0.log

So just simply run this following command and add some changes:

npm install npm-watch

You have to add npm-watch to the packages.json

 "scripts": {
    "dev": "vite",
    "build": "vite build",
    "watch": "npm-watch",
    "gsw": "workbox injectManifest workbox-config.js",
    "prod": "npm run build && npm run gsw && npm run usw",
    "usw": "node-minify --compressor uglify-es --input './public/service-worker.js' --output './public/sw.js'"
  },

"watch": {
    "build": {
      "patterns": [
        "src"
      ],
      "extensions": "js,jsx"
    }
  }

and then after run command-

npm run watch