issue with npm run watch

Published 4 months ago by afoysal

I am working on a vue.js project. When I am trying to run npm run watch I am getting below error.

enter image description here

Here is my composer.json file code

"scripts": {
    "dev": "node build/dev-server.js",
    "start": "node build/dev-server.js",
    "build": "node build/build.js"
  },

How can I solve this ?

MaverickChan

run npm install first

ejdelmonico

Are you using a custom build tool instead of mix? Laravel version?

afoysal

Thanks @MaverickChan . I am getting below output now.

enter image description here

afoysal

Thanks @ejdelmonico . I am using vue-cli. I am trying to build SPA. I am using Laravel for backend API purpose. Thanks.

ejdelmonico

The command is npm run dev

ok, you should the below if you used the webpack-simple skelton.

"scripts": {
    "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
    "build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
  }

You can add "build": "node build/build.js"

afoysal

Thanks @ejdelmonico for your reply. Sorry, I failed to understand. Should I use below code in package.json ?

"scripts": {
    "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
    "build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
  }
ejdelmonico

Well, the answer to that lies in which template you chose. The one I use the most is webpack-simple. With that template, you must run npm install. The script alias' in the package is what vue-cli produces so I would either adapt what you have now or run the vue-cli again and choose either webpack template. The full template runs npm install for you and contains a build command but if you are not going to write tests or write them in a custom way then use the webpack-simple.

Also, make sure you are using the latest vue-cli v2.9.3.

afoysal

Thanks @ejdelmonico for your reply. I need a step by step guide to have the command npm run watch. I am using Linux Mint 18.3. How to know the version of vue-cli ? What should I do if my version is not v2.9.3 ? Thanks.

ejdelmonico

Check the vue-cli version in terminal with vue -V. Post you package.json so that I can tell which template you chose.

afoysal

Here is the output of vue -V.

enter image description here

Here is the package.json

{
  "name": "my-project-front",
  "version": "1.0.0",
  "description": "A Vue.js project",
  "author": "foysal",
  "private": true,
  "scripts": {
    "dev": "node build/dev-server.js",
    "start": "node build/dev-server.js",
    "build": "node build/build.js",
    "watch": "npm-watch"
  },
  "dependencies": {
    "npm": "^5.7.1",
    "npm-watch": "^0.3.0",
    "sweetalert": "^2.1.0",
    "v-data-table": "^2.0.1",
    "vue": "^2.4.2",
    "vue-js-modal": "^1.3.6",
    "vue-resource": "^1.3.4",
    "vue-router": "^2.7.0",
    "vue-ya-semantic-modal": "0.0.3"
  },
  "devDependencies": {
    "autoprefixer": "^7.1.2",
    "babel-core": "^6.22.1",
    "babel-loader": "^7.1.1",
    "babel-plugin-transform-runtime": "^6.22.0",
    "babel-preset-env": "^1.3.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-2": "^6.22.0",
    "babel-register": "^6.22.0",
    "chalk": "^2.0.1",
    "connect-history-api-fallback": "^1.3.0",
    "copy-webpack-plugin": "^4.0.1",
    "css-loader": "^0.28.0",
    "cssnano": "^3.10.0",
    "eventsource-polyfill": "^0.9.6",
    "express": "^4.14.1",
    "extract-text-webpack-plugin": "^2.0.0",
    "file-loader": "^0.11.1",
    "friendly-errors-webpack-plugin": "^1.1.3",
    "html-webpack-plugin": "^2.28.0",
    "http-proxy-middleware": "^0.17.3",
    "opn": "^5.1.0",
    "optimize-css-assets-webpack-plugin": "^2.0.0",
    "ora": "^1.2.0",
    "rimraf": "^2.6.0",
    "semver": "^5.3.0",
    "shelljs": "^0.7.6",
    "url-loader": "^0.5.8",
    "vue-loader": "^13.0.4",
    "vue-style-loader": "^3.0.1",
    "vue-template-compiler": "^2.3.3",
    "webpack": "^2.6.1",
    "webpack-bundle-analyzer": "^2.2.1",
    "webpack-dev-middleware": "^1.10.0",
    "webpack-hot-middleware": "^2.18.0",
    "webpack-merge": "^4.1.0"
  },
  "engines": {
    "node": ">= 4.0.0",
    "npm": ">= 3.0.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]
}
ejdelmonico

How did you create your project? Did you use the vue-cli? If you created the project with the vue-cli, then you should have received a version number.

Please sign in or create an account to participate in this conversation.