1、问题现象

通过npm run dev 运行命令启动Vue项目时提示:

d>npm run dev
npm error Missing script: "dev"
npm error
npm error To see a list of scripts, run:
npm error   npm run
npm error A complete log of this run can be found in: C:\Users\admin\AppData\Local\npm-cache\_logs\2025-10-28T08_37_42_725Z-debug-0.log

2、问题原因

执行npm run dev 时,会读取package.json文件中的scripts字段,找到名为dev的脚本并执行它。
查看当前项目的package.json文件:

"scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  }

可见没有dev这个字段。
但我当下里面有serve,所以可以通过npm run serve来运行

>npm run serve
> hello-world@0.1.0 serve
> vue-cli-service serve
Browserslist: caniuse-lite is outdated. Please run:
  npx update-browserslist-db@latest
  Why you should do it regularly: https://github.com/browserslist/update-db#readme
 INFO  Starting development server...
 DONE  Compiled successfully in 9033ms                                                                          16:57:14
  App running at:
  - Local:   http://localhost:8091/
  - Network: http://192.168.0.164:8091/
  Note that the development build is not optimized.
  To create a production build, run npm run build.

 WAIT  Compiling...                                                                                             16:57:14
Compiling...

 DONE  Compiled successfully in 219ms                                                                           16:57:14

  App running at:
  - Local:   http://localhost:8091/
  - Network: http://192.168.0.164:8091/

这样就可以启动了。
将对应的服务地址放到浏览器地址栏即可访问。

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐