Heroku 网站:npm 错误!缺少脚本:开始

Posted

技术标签:

【中文标题】Heroku 网站:npm 错误!缺少脚本:开始【英文标题】:Heroku web: npm ERR! missing script: start 【发布时间】:2016-10-16 09:09:04 【问题描述】:

Heroku web 抛出错误:npm ERR! missing script: start

但是,当我在本地运行它时:heroku local web 它工作正常。 项目已成功构建。

我在 package.json 中将启动脚本设置为:

"scripts": 
    "start": "node server"
  

根据文档,如果我不指定 Procfile,默认情况下应该采用 npm start

不过,我也尝试添加 Procfile:

Procfile 内容。

web: npm start

它会抛出同样的错误。

日志输出:heroku logs -a nypstest

Niteshs-MacBook-Pro:nyps nitesh$ heroku logs -a nypstest
2016-06-15T07:01:44.024250+00:00 heroku[api]: Release v3 created by nitesh@campusdiaries.com
2016-06-15T07:01:44.023668+00:00 heroku[api]: Scale to web=1 by nitesh@campusdiaries.com
2016-06-15T07:01:44.429595+00:00 heroku[slug-compiler]: Slug compilation started
2016-06-15T07:01:44.429603+00:00 heroku[slug-compiler]: Slug compilation finished
2016-06-15T07:01:46.222149+00:00 heroku[web.1]: Starting process with command `npm start`
2016-06-15T07:01:49.138230+00:00 app[web.1]: npm ERR! Linux 3.13.0-85-generic
2016-06-15T07:01:49.141111+00:00 app[web.1]: npm ERR! npm  v3.8.6
2016-06-15T07:01:49.139367+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-06-15T07:01:49.139986+00:00 app[web.1]: npm ERR! node v5.11.1
2016-06-15T07:01:49.160916+00:00 app[web.1]: 
2016-06-15T07:01:49.145755+00:00 app[web.1]: npm ERR! 
2016-06-15T07:01:49.146073+00:00 app[web.1]: npm ERR! If you need help, you may report this error at:
2016-06-15T07:01:49.143580+00:00 app[web.1]: 
2016-06-15T07:01:49.146389+00:00 app[web.1]: npm ERR!     <https://github.com/npm/npm/issues>
2016-06-15T07:01:49.161685+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-06-15T07:01:49.161369+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-06-15T07:01:49.145444+00:00 app[web.1]: npm ERR! missing script: start
2016-06-15T07:01:50.132213+00:00 heroku[web.1]: Process exited with status 1
2016-06-15T07:01:50.152654+00:00 heroku[web.1]: State changed from crashed to starting
2016-06-15T07:01:50.151676+00:00 heroku[web.1]: State changed from starting to crashed
2016-06-15T07:01:52.430686+00:00 heroku[web.1]: Starting process with command `npm start`
2016-06-15T07:01:55.754745+00:00 app[web.1]: npm ERR! node v5.11.1
2016-06-15T07:01:55.753213+00:00 app[web.1]: npm ERR! Linux 3.13.0-85-generic
2016-06-15T07:01:55.759649+00:00 app[web.1]: npm ERR! If you need help, you may report this error at:
2016-06-15T07:01:55.754205+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-06-15T07:01:55.755673+00:00 app[web.1]: npm ERR! npm  v3.8.6
2016-06-15T07:01:55.759409+00:00 app[web.1]: npm ERR! 
2016-06-15T07:01:55.759143+00:00 app[web.1]: npm ERR! missing script: start
2016-06-15T07:01:55.757612+00:00 app[web.1]: 
2016-06-15T07:01:55.759874+00:00 app[web.1]: npm ERR!     <https://github.com/npm/npm/issues>
2016-06-15T07:01:55.772868+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-06-15T07:01:55.772730+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-06-15T07:01:55.772370+00:00 app[web.1]: 
2016-06-15T07:01:56.675716+00:00 heroku[web.1]: Process exited with status 1
2016-06-15T07:01:56.687035+00:00 heroku[web.1]: State changed from starting to crashed
2016-06-15T07:03:23.527948+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nypstest.herokuapp.com request_id=b064f04d-b6b8-4655-adc4-c4bbdb4db70a fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
2016-06-15T07:03:26.783968+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nypstest.herokuapp.com request_id=dfa98acd-5291-46df-85e6-ec2d7bd1afa0 fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
2016-06-15T07:25:30.940961+00:00 heroku[web.1]: State changed from crashed to starting
2016-06-15T07:25:33.374221+00:00 heroku[web.1]: Starting process with command `npm start`
2016-06-15T07:25:35.711736+00:00 app[web.1]: npm ERR! Linux 3.13.0-85-generic
2016-06-15T07:25:35.712514+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-06-15T07:25:35.712824+00:00 app[web.1]: npm ERR! node v5.11.1
2016-06-15T07:25:35.713260+00:00 app[web.1]: npm ERR! npm  v3.8.6
2016-06-15T07:25:35.714628+00:00 app[web.1]: 
2016-06-15T07:25:35.716136+00:00 app[web.1]: npm ERR! missing script: start
2016-06-15T07:25:35.716418+00:00 app[web.1]: npm ERR! 
2016-06-15T07:25:35.716638+00:00 app[web.1]: npm ERR! If you need help, you may report this error at:
2016-06-15T07:25:35.716866+00:00 app[web.1]: npm ERR!     <https://github.com/npm/npm/issues>
2016-06-15T07:25:35.726294+00:00 app[web.1]: 
2016-06-15T07:25:35.726558+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-06-15T07:25:35.726717+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-06-15T07:25:36.541486+00:00 heroku[web.1]: State changed from starting to crashed
2016-06-15T07:25:36.529432+00:00 heroku[web.1]: Process exited with status 1
2016-06-15T07:25:55.677715+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nypstest.herokuapp.com request_id=d67c3c7f-1b0c-4ae4-8066-f539c676c813 fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
2016-06-15T07:25:56.970694+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nypstest.herokuapp.com request_id=a5e959df-5c6b-475e-883d-668fffc3b1ca fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
2016-06-15T07:37:15.873210+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nypstest.herokuapp.com request_id=83d3f406-22ba-4649-81c4-261889c6f26d fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
2016-06-15T07:37:17.263994+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nypstest.herokuapp.com request_id=b24ecc40-99ed-4ee4-8975-850f02880751 fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
2016-06-15T07:40:31.730476+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nypstest.herokuapp.com request_id=46c7351c-6818-466c-b816-fab8686a3a26 fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
2016-06-15T07:40:32.902969+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nypstest.herokuapp.com request_id=a29d2281-9931-412d-befb-4788284e6dc3 fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
2016-06-15T07:40:46.425659+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nypstest.herokuapp.com request_id=69f32408-7b94-41ed-a692-3874bb87125e fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
2016-06-15T07:40:47.283575+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nypstest.herokuapp.com request_id=82645270-a085-49f0-8bdd-8ffbd417e136 fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
2016-06-15T07:46:45.562741+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nypstest.herokuapp.com request_id=d6b356f1-e7f3-4e74-a9bc-7834b6ddaa39 fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
2016-06-15T07:46:46.792388+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nypstest.herokuapp.com request_id=0df4dfd9-5368-41b3-a658-37c80effc3c5 fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
2016-06-15T08:09:20.166494+00:00 heroku[web.1]: State changed from crashed to starting
2016-06-15T08:09:22.215228+00:00 heroku[web.1]: Starting process with command `npm start`
2016-06-15T08:09:25.009624+00:00 app[web.1]: npm ERR! Linux 3.13.0-85-generic
2016-06-15T08:09:25.010335+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-06-15T08:09:25.010667+00:00 app[web.1]: npm ERR! node v5.11.1
2016-06-15T08:09:25.011377+00:00 app[web.1]: npm ERR! npm  v3.8.6
2016-06-15T08:09:25.013096+00:00 app[web.1]: 
2016-06-15T08:09:25.014247+00:00 app[web.1]: npm ERR! missing script: start
2016-06-15T08:09:25.014442+00:00 app[web.1]: npm ERR! 
2016-06-15T08:09:25.014622+00:00 app[web.1]: npm ERR! If you need help, you may report this error at:
2016-06-15T08:09:25.014765+00:00 app[web.1]: npm ERR!     <https://github.com/npm/npm/issues>
2016-06-15T08:09:25.025073+00:00 app[web.1]: 
2016-06-15T08:09:25.025367+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-06-15T08:09:25.025542+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-06-15T08:09:25.854231+00:00 heroku[web.1]: State changed from starting to crashed
2016-06-15T08:09:25.844519+00:00 heroku[web.1]: Process exited with status 1
2016-06-15T08:26:54.120685+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nypstest.herokuapp.com request_id=8e5dbaff-ba8a-4a2f-a4f5-b56e6aba2871 fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
2016-06-15T08:26:55.251426+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nypstest.herokuapp.com request_id=ada7aaf7-a2c6-4f98-b387-3f201102b09c fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
2016-06-15T08:36:41.113185+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nypstest.herokuapp.com request_id=e412adc8-0d6f-45c9-b30d-06774366132e fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
2016-06-15T08:36:42.534191+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nypstest.herokuapp.com request_id=bcc98a01-93d2-40b8-91ce-d59f67f54c7a fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
2016-06-15T09:32:52.373988+00:00 heroku[web.1]: State changed from crashed to starting
2016-06-15T09:32:54.422584+00:00 heroku[web.1]: Starting process with command `npm start`
2016-06-15T09:32:57.749315+00:00 app[web.1]: npm ERR! Linux 3.13.0-85-generic
2016-06-15T09:32:57.751518+00:00 app[web.1]: npm ERR! npm  v3.8.6
2016-06-15T09:32:57.753827+00:00 app[web.1]: 
2016-06-15T09:32:57.755515+00:00 app[web.1]: npm ERR! 
2016-06-15T09:32:57.750410+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-06-15T09:32:57.750924+00:00 app[web.1]: npm ERR! node v5.11.1
2016-06-15T09:32:57.755280+00:00 app[web.1]: npm ERR! missing script: start
2016-06-15T09:32:57.773805+00:00 app[web.1]: 
2016-06-15T09:32:57.755821+00:00 app[web.1]: npm ERR!     <https://github.com/npm/npm/issues>
2016-06-15T09:32:57.755662+00:00 app[web.1]: npm ERR! If you need help, you may report this error at:
2016-06-15T09:32:57.774094+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-06-15T09:32:57.774273+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-06-15T09:32:58.841956+00:00 heroku[web.1]: State changed from starting to crashed
2016-06-15T09:32:58.826851+00:00 heroku[web.1]: Process exited with status 1
2016-06-15T09:49:37.707537+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nypstest.herokuapp.com request_id=bc832c95-120e-4b59-ad83-7dd95f7081f8 fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
2016-06-15T09:49:39.156404+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nypstest.herokuapp.com request_id=0f6b252e-8e67-47b1-9c21-c41eea09e0ef fwd="106.51.141.204" dyno= connect= service= status=503 bytes=
Niteshs-MacBook-Pro:nyps nitesh$ 

包.json

  ...app descriptions

  "main": "index.js",
  "scripts": 
    "start": "node server"
  ,

  ...other dependencies

server.js

var webpack = require('webpack')
var webpackDevMiddleware = require('webpack-dev-middleware')
var webpackHotMiddleware = require('webpack-hot-middleware')
var config = require('./webpack.config')
var serveStatic = require('serve-static');
var sendMail = require('./src/api/sendmail');
var bodyParser = require('body-parser');
var app = new (require('express'))()

var port = process.env.WEBPACK_PORT || 3000

var compiler = webpack(config)
app.use(webpackDevMiddleware(compiler,  noInfo: true, publicPath: config.output.publicPath ))
app.use(webpackHotMiddleware(compiler))

// parse application/json
app.use(bodyParser.json());

    // parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded( extended: true ));


app.get('*', function(req, res) 
  res.sendFile(__dirname + '/index.html')
)




app.listen(port, function(error) 
  if (error) 
    console.error(error)
   else 
    console.info("==> ????  Listening on port %s. Open up http://localhost:%s/ in your browser.", port, port)
  
)

编辑: 完成Package.json


  "name": "App_Name",
  "version": "1.0.0",
  "description": "Some-Discription",
  "keywords": [
    "redux",
    "react",
    "router",
    "routing",
    "frontend",
    "client",
    "webpack",
    "babel",
    "sass",
    "foundation",
    "postcss"
  ],
  "main": "index.js",
  "scripts": 
    "start": "node server.js",
    "test": "mocha",
    "postinstall": "bower install && grunt build"
  ,
  "author": "Nitesh",
  "license": "ISC",
  "dependencies": 
    "axios": "^0.11.1",
    "body-parser": "^1.15.1",
    "classnames": "^2.2.0",
    "connect": "^3.4.1",
    "firebase": "^3.0.3",
    "firebase-token-generator": "^2.0.0",
    "font-awesome": "^4.3.0",
    "foundation-sites": "^6.1.2",
    "json-loader": "^0.5.4",
    "mongodb": "^2.1.20",
    "mongoose": "^4.4.19",
    "react": "^0.14.5",
    "react-addons-update": "^0.14.7",
    "react-autosuggest": "^3.7.4",
    "react-dom": "^0.14.7",
    "react-modal": "^1.3.0",
    "react-router": "2.0.0-rc5",
    "react-router-redux": "^2.1.0",
    "react-simple-autocomplete": "^1.0.2",
    "redux": "^3.2.1",
    "redux-form": "^5.2.5",
    "redux-logger": "^2.5.2",
    "redux-thunk": "^1.0.3",
    "request": "^2.65.0",
    "rethinkdb": "^2.3.1",
    "sendgrid": "^2.0.0",
    "underscore": "^1.8.3",
    "what-input": "^1.1.4"
  ,
  "optionalDependencies": ,
  "devDependencies": 
    "autoprefixer": "^6.3.2",
    "babel-core": "^6.3.15",
    "babel-loader": "^6.2.0",
    "babel-plugin-transform-runtime": "^6.5.0",
    "babel-preset-es2015": "^6.3.13",
    "babel-preset-react": "^6.3.13",
    "babel-preset-react-hmre": "^1.0.1",
    "babel-preset-stage-0": "^6.5.0",
    "babel-runtime": "^6.9.0",
    "css-loader": "^0.23.1",
    "express": "^4.13.3",
    "extract-text-webpack-plugin": "^1.0.1",
    "file-loader": "^0.8.5",
    "jquery": "^2.2.4",
    "node-sass": "^3.4.2",
    "postcss-loader": "^0.8.0",
    "react-redux": "^4.4.5",
    "redux-devtools": "^3.1.0",
    "redux-devtools-dock-monitor": "^1.0.1",
    "redux-devtools-log-monitor": "^1.0.3",
    "sass-loader": "^3.1.2",
    "script-loader": "^0.6.1",
    "serve-static": "^1.10.2",
    "style-loader": "^0.13.0",
    "url-loader": "^0.5.7",
    "webpack": "^1.9.11",
    "webpack-dev-middleware": "^1.2.0",
    "webpack-hot-middleware": "^2.2.0"
  

【问题讨论】:

你能发布你的完整package.json吗? 您好,感谢您的回复。我已经添加了完整的 package.json。 请查看您的package json's scripts section 【参考方案1】:

您必须将 package.json 中的“main”更改为 server.js

你也可以这样做:

"scripts": 
  "start": "node server.js",
  "test": "mocha",
  "postinstall": "bower install && grunt build"

https://devcenter.heroku.com/articles/nodejs-support#customizing-the-build-process

https://scotch.io/tutorials/how-to-deploy-a-node-js-app-to-heroku

【讨论】:

您好,感谢您的回复。我试着这样做。那也没用。 作为替代方案,您可以在 Procfile 中指定: web: node index.js ** 参见***.com/questions/34631300/…【参考方案2】:

我遇到了同样的问题,我的服务器在 app.js 文件上,我将 package.json 文件更改如下:

"main": "app.js",
"scripts": 
    "test": "echo \"Error: no test specified\" && exit 1",
    "start" : "node app.js"
  ,

Procfile 为

web: node app.js

然后我重做 heroku 创建过程 heroku app create procedure

这是它的链接:https://devcenter.heroku.com/articles/deploying-nodejs#deploy-your-application-to-heroku

我认为这会有所帮助

【讨论】:

【参考方案3】:

一切看起来都正确。确保 Procfile 命名正确并且位于正确的文件夹中。

【讨论】:

【参考方案4】:

问题可能在于您的文件是如何嵌套的。如果您有一个 git 存储库,其中包含另一个包含代码的文件,则 pa

【讨论】:

您是否不小心删除了部分答案?最后一句话似乎不完整。【参考方案5】:

我有三个同名的js以及我的主js文件,它对我有用。

在 package.json 中。"main": "app.js", "scripts": "start": "node app.js"

在 Procfileweb:node app.js

【讨论】:

以上是关于Heroku 网站:npm 错误!缺少脚本:开始的主要内容,如果未能解决你的问题,请参考以下文章

Npm 错误!缺少脚本:部署到 heroku 时开始

Discord.js 机器人 | Heroku 部署错误 | npm 错误!缺少脚本:开始

npm 错误!缺少脚本:将反应应用程序部署到heroku时构建

如何修复 npm ERR!缺少脚本:从反应开始

反应:缺少脚本:开始

得到错误!缺少脚本:在 <npm start> 命令上启动