【问题标题】:Why am I getting an npm missing server error on Vue.js?为什么我在 Vue.js 上收到 npm 缺少服务器错误?
【发布时间】:2019-02-19 09:28:29
【问题描述】:

我刚刚安装了 Node.js 和 Vue.js,并在 Vue 上创建了我的第一个名为 test 的项目。我现在正在尝试通过键入 cmd 来设置服务器:

npm run server

但我收到以下错误:

C:\Users\andri\test>npm run server
npm ERR! missing script: server

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\andri\AppData\Roaming\npm-cache\_logs\2019-02-19T09_12_53_961Z-debug.log

谁能帮助我了解我缺少什么?我用谷歌搜索了一下,但到目前为止还没有找到解决方案。我很感激,任何帮助!

编辑:这是我的 package.json 文件

{
  "name": "test",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "vue": "^2.5.22"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^3.4.0",
    "@vue/cli-plugin-eslint": "^3.4.0",
    "@vue/cli-service": "^3.4.0",
    "babel-eslint": "^10.0.1",
    "eslint": "^5.8.0",
    "eslint-plugin-vue": "^5.0.0",
    "vue-template-compiler": "^2.5.21"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "rules": {},
    "parserOptions": {
      "parser": "babel-eslint"
    }
  },
  "postcss": {
    "plugins": {
      "autoprefixer": {}
    }
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]
}

【问题讨论】:

  • 你能显示你的 package.json 文件吗?
  • @MohammadRaheem 我更新了问题并将其包含在内
  • 你应该运行:npm run serve,而不是 server...

标签: javascript node.js vue.js npm


【解决方案1】:

npm run server 替换为npm run serve

说明

package.json 键下的scripts 中,您没有server 脚本。但是您确实有一个serve。要使用npm run 运行某个脚本它需要在scripts 中,在您的package.json

【讨论】:

    【解决方案2】:

    1-先输入以下内容

    vue add @vue/cli-service
    

    2- 如果没有,则在 package.json 中添加以下代码

    “脚本”:{ "serve": "vue-cli-service serve", “构建”:“vue-cli-服务构建” },

    3- type code ==> npm run serve npm run build for build

    npm run serve 
    

    或跟随构建

    npm run build
    

    如果只是不起作用,您只需运行以下并再次重复

    npm install
    
    npm init
    

    【讨论】:

      【解决方案3】:

      在终端中首先输入:

      npm install
      npm start
      npm run serve
      

      我通过这种方式解决了我的问题,它在我的电脑上完美运行。

      【讨论】:

        【解决方案4】:

        只需转到包含以下内容的正确目录:

        .idea

        节点模块

        公开

        源代码 .

        .

        .

        然后再写 npm run serve

        就这个

        【讨论】:

          猜你喜欢
          • 2020-01-08
          • 1970-01-01
          • 1970-01-01
          • 2017-12-30
          • 2019-10-25
          • 2020-05-03
          • 1970-01-01
          • 2019-02-06
          • 1970-01-01
          相关资源
          最近更新 更多