在 heroku 中上传失败

Upload in heroku fails

我制作了这个应用程序,我想托管它。 我选择 heroku 但在构建过程中出现以下错误

Error: Cannot find module '/tmp/build_dcf81a5e/index.js'

注意:我没有使用 vue next react 或我只是使用的任何其他类型的 js Node js

如果有人想要整个日志,请查看这些图片
[记录第 1 部分(构建)https://i.stack.imgur.com/xSKbt.png]

[日志第 2 部分(发生错误)https://i.stack.imgur.com/tz8gL.png]

如果需要,请使用我的 git 源代码库 https://github.com/rohanCoderMan/AceBook Package.json如下

  
{
  "name": "nodejsapp",
  "version": "0.0.1",
  "description": "This is an app that we'll create showing off the basics of node.js",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon app",
    "build": "nodemon app"
  },
  "author": "rdzfinalrounduser",
  "license": "MIT",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.19.0",
    "connect": "^3.7.0",
    "connect-flash": "^0.1.1",
    "cookie-parser": "^1.4.5",
    "ejs": "^3.1.6",
    "express": "^4.17.1",
    "express-session": "^1.17.2",
    "flash": "^1.1.0",
    "mongoose": "^5.12.12",
    "multer": "^1.4.2",
    "nodemon": "^2.0.7",
    "passport": "^0.4.1",
    "passport-local": "^1.0.0",
    "path": "^0.12.7"
  }
}

如果需要更多信息,请在下面评论,我已尽力让这个问题清楚(如果我犯了一个愚蠢的错误,请不要苛刻,我只是在学习) 提前致谢

首先,查看 heroku 文档以查看部署周期。基本上,构建脚本在安装包之后是 运行(这通常用于捆绑前端代码,但有时也用于编译服务器代码,就像您使用 TypeScript 一样)。由于您没有完成任何构建,因此您应该在 package.json 文件中删除该行。 (基本上,您在这里所做的就是启动您的服务器两次)

此外,Heroku 有自己的进程监视器,因此无需使用 nodemon。将启动脚本更改为 node app.js。您还可以添加一个使用 nodemon 进行本地开发的开发脚本,然后 运行 使用 npm run dev.

总而言之,将 package.json 文件中的脚本配置更改为以下内容:

   ...
   "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1",
      "start": "node app.js",
      "dev": "nodemon app.js",
  },
  ...

此外,您需要在 package.json 文件旁边有一个 app.js 文件,您可以在该文件中编写启动服务器的代码。看起来像 this file here

的东西