【问题标题】:npm ERR! missing script: start on herokunpm 错误!缺少脚本:从 heroku 开始
【发布时间】:2021-04-02 15:48:41
【问题描述】:

您好,我正在尝试通过我的 github 将应用程序部署到 heroku。我修改了 package.json 中的启动脚本以进入 src 文件,其中有 app.js 应该是服务器端文件。

这是我的 package.json:

{
  "name": "server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "./node_modules/nodemon/bin/nodemon.js src/app.js --exec 'npm run lint && node'",
    "lint": "eslint \"**/*.js\"",
    "start": "node src/app.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "morgan": "^1.10.0",
    "nodemon": "^2.0.7"
  },
  "devDependencies": {
    "eslint": "^7.23.0",
    "eslint-plugin-vue": "^7.8.0"
  }
}

这是文件目录:

这是 app.js 文件中的代码:

console.log("hello")
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const morgan = require('morgan')

const app = express()

app.use(morgan('combine'))
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cors())

app.get('/status', (req,res)=>{
    res.send({
        message: 'hello world!'
    })


})

app.listen(process.env.PORT || 8081)

我从 Heroku 得到的完整错误信息是:

2021-04-02T15:36:38.339680+00:00 heroku[web.1]: Starting process with command `npm start`
2021-04-02T15:36:43.511317+00:00 heroku[web.1]: Process exited with status 1
2021-04-02T15:36:43.688509+00:00 heroku[web.1]: State changed from starting to crashed
2021-04-02T15:36:43.392349+00:00 app[web.1]: npm ERR! missing script: start
2021-04-02T15:36:43.424949+00:00 app[web.1]: 
2021-04-02T15:36:43.425845+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-04-02T15:36:43.426219+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2021-04-02T15_36_43_393Z-debug.log
2021-04-02T15:36:44.616474+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=tft-training-tool.herokuapp.com request_id=7c11d9b2-66b5-4daf-ba1d-ad3c22e0706a fwd="90.255.93.115" dyno= connect= service= status=503 bytes= protocol=https
2021-04-02T15:36:44.843068+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=tft-training-tool.herokuapp.com request_id=3411084a-5fa2-4563-96b9-879b3735f80a fwd="90.255.93.115" dyno= connect= service= status=503 bytes= protocol=https 

【问题讨论】:

  • 可能是我通过github部署但package.json不在服务器文件夹下的主目录中的问题吗?

标签: javascript node.js express heroku


【解决方案1】:

您似乎有一个包含 package.jsonpackage-lock.json 的文件夹,这是包含另外两个文件夹 clientserver 的根文件夹,它们有自己的 package.jsonpackage-lock.json 文件(至少我在上图中看到的 server 文件夹,因此您在服务器文件夹中的package.json 中为服务器配置了脚本。因为 Heroku 将所有存储库拉到一起,所以它需要 package.jsonroot 文件夹内作为服务器的配置,似乎不包含start 脚本。

【讨论】:

    猜你喜欢
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 2017-10-16
    • 1970-01-01
    • 2018-12-22
    • 2021-04-26
    • 1970-01-01
    相关资源
    最近更新 更多