运行全新的VUE JS Hello.word App时出错

时间:2020-02-12 16:25:13

标签: vue.js npm

我正在尝试运行我的第一个应用程序。我是通过CLI创建的:vue create hello-world 当我尝试使用CLI启动应用程序时:npm run serve,该应用程序运行。 当我尝试通过CLI启动应用程序时:npm run dev,应用程序将向我返回以下错误。

PS C:\Users\Administrator\hello-world> npm install -g npm@latest
C:\Users\Administrator\AppData\Roaming\npm\npx -> C:\Users\Administrator\AppData\Roaming\npm\node_modules\npm\bin\npx-cli.js
C:\Users\Administrator\AppData\Roaming\npm\npm -> C:\Users\Administrator\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
+ npm@6.13.7
added 434 packages from 860 contributors in 14.601s
PS C:\Users\Administrator\hello-world> npm run dev
npm ERR! missing script: dev

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2020-02-12T16_06_26_201Z-debug.log

这是我的packagejson:

{
    "name": "hello-world",
    "version": "0.1.0",
    "private": true,
    "scripts": {
        "serve": "vue-cli-service serve",
        "build": "vue-cli-service build",
        "lint": "vue-cli-service lint"

    },
    "dependencies": {
        "core-js": "^3.6.4",
        "vue": "^2.6.11"
    },
    "devDependencies": {
        "@vue/cli-plugin-babel": "^4.2.0",
        "@vue/cli-plugin-eslint": "^4.2.0",
        "@vue/cli-service": "^4.2.0",
        "babel-eslint": "^10.0.3",
        "eslint": "^6.7.2",
        "eslint-plugin-vue": "^6.1.2",
        "vue-template-compiler": "^2.6.11"
    },
    "eslintConfig": {
        "root": true,
        "env": {
            "node": true
        },
        "extends": [
            "plugin:vue/essential",
            "eslint:recommended"
        ],
        "parserOptions": {
            "parser": "babel-eslint"
        },
        "rules": {}
    },
    "browserslist": [
        "> 1%",
        "last 2 versions"
    ]
}

    PS C:\Users\Administrator

我还尝试将新行放入package.json中:"dev": "vue-cli-service dev"
但我收到此错误:

> vue-cli-service dev

 ERROR  command "dev" does not exist.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hello-world@0.1.0 dev: `vue-cli-service dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hello-world@0.1.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2020-02-12T16_23_48_785Z-debug.log

1 个答案:

答案 0 :(得分:1)

npm run命令执行您已经在package.json文件中的脚本部分定义的一条指令。

简单来说,在package.json文件的脚本部分定义的命令将在终端命令行上执行。

您可以在此部分中定义自定义脚本。您执行了此操作,并在键入npm run dev时,在package.json文件的scripts部分中定义的脚本被执行为vue-cli-service dev。但是指令devvue-cli-service中不存在。 您正在寻找的命令可能是vue-cli-service serve,它将启动一个webpack dev server实例,并且与npm run serve基本上相同。