Home > Back-end >  "npm run watch" not working and returning error's saying 'missing "Watch&qu
"npm run watch" not working and returning error's saying 'missing "Watch&qu

Time:07-28

In my fresh laravel project after adding a tailwind template, I tried running npm run watch but it's not working, thus the template is not loading correctly either.

$ npm run watch                                                       
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\U-S-E-R\AppData\Local\npm-cache\_logs\2022-07-27T18_05_36_192Z-debug-0.log

Here is the Error Screenshot

CodePudding user response:

Do you have any script configured in package.json file for the watch command?

For Example, An angular application has added it out of the box like following:

......
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "prod": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  }
......

If you didn't have configured it in package.json file then you will get the error you mentioned.

CodePudding user response:

As someone says, new laravel projects do not have a watch is cript, now have vite instead of webpack, so you need to run npm run dev instead to let vite compile your files.

I dont know if its a kind of bug, but i have notice that when you install some dependency like npm instal laravel/ui (tailwind in your case), npm adds the webpack.mix.js file to the project (even when vite is already configured), so, i suggest you to follow this official tutorial to migrate from vite to webpack if you want to keep working with webpack as always has been, or search how to integrate dependencies to your project with vite to keep using it.

  • Related