简体   繁体   English

为什么我在 Vue.js 上收到 npm missing server 错误?

[英]Why am I getting an npm missing server error on Vue.js?

I just installed Node.js and Vue.js and created my first project on Vue called test .我刚刚安装了 Node.js 和 Vue.js,并在 Vue 上创建了我的第一个名为test 的项目。 I am now trying to set up the server by typing on cmd:我现在正在尝试通过在 cmd 上键入来设置服务器:

npm run server

But I get the following error:但我收到以下错误:

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

Could anyone help me understand what I am missing?谁能帮助我了解我缺少什么? I googled a bit around, but have not been able to find a solution so far.我用谷歌搜索了一下,但到目前为止还没有找到解决方案。 I appreciate, any help!我很感激,任何帮助!

EDIT: This is my package.json file编辑:这是我的 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"
  ]
}

Replace npm run server with npm run serve更换npm run servernpm run serve

Explanation解释

In your package.json under the scripts key you don't have a server script.scripts键下的package.json ,您没有server脚本。 But you do have a serve one.但你确实有一个serve To run a certain script with npm run it needs to be in scripts inside your package.json要使用npm run运行某个脚本,它需要在package.json中的scripts

First type in your terminal:首先在你的终端输入:

npm install
npm start
npm run serve

I solved my problem this way and it works perfectly on my PC.我以这种方式解决了我的问题,它在我的 PC 上完美运行。

1- type the folowing first 1-先输入以下内容

vue add @vue/cli-service

2- add following code to package.json if there were not 2- 如果没有,则将以下代码添加到 package.json

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

3- type code ==> npm run serve <=== for serve or type==> npm run build for build <== 3- 输入代码==> npm run serve <=== for serve or type==> npm run build for build <==

npm run serve 

or following to build或以下构建

npm run build

if only doesnt work you just run following and reapeat again如果只是不起作用,您只需运行以下并再次重复

npm install

npm init

Just go to the right directory that contain :只需转到包含以下内容的正确目录:

.idea 。主意

node_modules节点模块

public民众

src .源文件。

. .

. .

and then write npm run serve again然后再次编写 npm run serve

Just this只是这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM