命令 npm 启动后"Missing script:start"错误



当我输入npm时,给出以下错误;

npm ERR! Linux 4.4.0-109-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "start"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! missing script: start
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

以下 package.json 在另一台服务器中工作。我尝试将我的 nodejs 应用程序部署到另一台服务器。我成功地安装了nodejs和npm。

注意:安装 npm 后,我的项目文件夹下没有node_modules文件夹。

我的包.json文件就像;

{
  "name": "myapplication",
  "version": "1.0.0",
  "description": "myapplication",
  "main": "index.js",
  "scripts": {
    "test": "mocha",
    "dev": "pm2 start ecosystem.config.js",
    "pro": "pm2 start ecosystem.config.js --env production"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "apn": "2.1.5",
    "async": "2.5.0",
    "body-parser": "1.17.2",
    "bootstrap": "3.3.7",
    "callback2promise": "1.0.3",
    "cookie-parser": "1.4.3",
    "express": "4.15.4",
    "express-session": "1.15.5",
    "geolib": "2.0.23",
    "image-type": "3.0.0",
    "jsonwebtoken": "7.4.3",
    "jimp": "0.2.28",
    "mkdirp": "0.5.1",
    "mongoose": "4.11.9",
    "morgan": "1.8.2",
    "multer": "1.3.0",
    "node-gcm": "0.14.6",
    "nodemailer": "4.1.0",
    "shortid": "2.2.8",
    "socket.io": "2.0.3",
    "socket.io-redis": "5.2.0",
    "twitter": "1.7.1",
    "underscore-node": "0.1.2",
    "bcrypt": "1.0.3" 
  },
  "devDependencies": {
    "eslint": "4.5.0"
  }
}

要下载并安装 node_modules/ 文件夹中的所有模块,您需要使用 install 而不是 start 。由于start不是由npm预定义的,如果要使用注释,则需要为其定义自定义脚本。

因此install是下载和安装所有模块的默认命令,具体取决于您的package.json

$ npm install

只需使用以下命令在您的系统上全局重新安装创建-反应-应用程序包,它应该可以工作。

npm install -g create-react-app

然后使用以下命令创建 React 应用程序

create-react-app <your app name>

然后转到您的应用目录并运行"npm start"命令。

在脚本字典中将"test"更改为"start",如下所示:

  {
    "name": "myapplication",
    "version": "1.0.0",
    "description": "myapplication",
    "main": "index.js",
    "scripts": {
    "**start**": "mocha",
    "dev": "pm2 start ecosystem.config.js",
    "pro": "pm2 start ecosystem.config.js --env production"
  },
  "author": "",
  "license": "ISC",
  "dependencies": 
  {
    "apn": "2.1.5",
    "async": "2.5.0",
    "body-parser": "1.17.2",
    "bootstrap": "3.3.7",
    "callback2promise": "1.0.3",
    "cookie-parser": "1.4.3",
    "express": "4.15.4",
    "express-session": "1.15.5",
    "geolib": "2.0.23",
    "image-type": "3.0.0",
    "jsonwebtoken": "7.4.3",
    "jimp": "0.2.28",
    "mkdirp": "0.5.1",
    "mongoose": "4.11.9",
    "morgan": "1.8.2",
    "multer": "1.3.0",
    "node-gcm": "0.14.6",
    "nodemailer": "4.1.0",
    "shortid": "2.2.8",
    "socket.io": "2.0.3",
    "socket.io-redis": "5.2.0",
    "twitter": "1.7.1",
    "underscore-node": "0.1.2",
    "bcrypt": "1.0.3" 
  },
  "devDependencies": 
  {
    "eslint": "4.5.0"
  }
}

这是对我有用的适当解决方案。我用了

"scripts": 
{
     .
     .
    "**start**": "webpack-dev-server --open",
     .
     .
}

因为我使用"webpack"作为加载器。

在 package.json 文件中添加启动脚本

{
  "version": "1.0.0",
  "description": "No description",
  "main": "index.js",
  "scripts": {
    ...
    "start": "node index.js"
    ...
  },
  "license": "Unlicense",
  "private": true,
  "dependencies": {
  },
  "devDependencies": {
  }
}

最新更新