如何解决npm ERR!缺少脚本:dev

Har*_*ssu 0 npm vue.js

我已经安装了node.js。接下来,我使用命令安装了cnmp

npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install
Run Code Online (Sandbox Code Playgroud)

当我尝试命令时cnpm run dev 出现错误:

npm ERR! path C:\Users\Harry\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\Harry\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Harry\AppData\Roaming\npm-cache\_logs\2018-08-03T02_48_22_663Z-debug.log
Run Code Online (Sandbox Code Playgroud)

所以我将package.json从C:\Users\Harry\AppData\Roaming\npm\node_modules\cnpm移到,'C:\Users\Harry\package.json' 但是仍然出现错误:

npm ERR! missing script: dev

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Harry\AppData\Roaming\npm-cache\_logs\2018-08-03T02_51_46_194Z-debug.log
Run Code Online (Sandbox Code Playgroud)

并且我还尝试了类似问题的方法,例如在package.json中编辑脚本,但该脚本仍然无法正常工作。

小智 5

也许您正在使用Vue CLI 3?如果是,则没有“ dev”构建脚本。Vue 2样板项目的早期版本具有“ dev”脚本-但不再存在。

而是使用“ serve”脚本,您的Vue项目将以dev运行

npm run serve
Run Code Online (Sandbox Code Playgroud)

请参阅package.json文件中使用Vue CLI 3配置的脚本

"scripts": {
         "serve": "vue-cli-service serve",
         "build": "vue-cli-service build",
         "lint": "vue-cli-service lint"    },
Run Code Online (Sandbox Code Playgroud)

希望能解决您的问题。