node.js - 从节点应用程序“未能检测到”构建包构建 Heroku
问题描述
我重新组织了我的应用程序,当我将其重建到我的 heroku 服务器上时,出现以下错误
remote: ! ERROR: Application not supported by 'heroku/nodejs' buildpack remote: ! remote: ! The 'heroku/nodejs' buildpack is set on this application, but was remote: ! unable to detect a Node.js codebase.
我知道这个问题可以通过重新排列我的文件夹结构来解决。我不想这样做,因为它按原样组织得很好。我想知道如何在不重组项目的情况下解决问题。
当前文件夹结构
\client\package.json
\client\node_modules
\client\{all other client files}
server\package.json
server\{all other server files}
server\none_modules
\wiki\{all wiki files}
.gitignore
我尝试过的
我已阅读建议将 package.json 放在根目录中的文章。我在那里尝试了一个名为 package.json 的空 json 文件,但它不起作用,因为我猜它实际上正在使用该文件,并且它想读取位于我的 \server 目录中的文件来运行构建脚本。
我想知道我是否可以只调用 heruku 在不同的目录中启动?
尝试 2
我尝试创建一个名为 Procfile 的文件并向其中添加以下内容
web: npm client
server: npm start
然后我创建了一个提交并运行
git push heroku master
我收到以下错误
emote: ! ERROR: Application not supported by 'heroku/nodejs' buildpack
remote: !
remote: ! The 'heroku/nodejs' buildpack is set on this application, but was
remote: ! unable to detect a Node.js codebase.
remote: !
remote: ! A Node.js app on Heroku requires a 'package.json' at the root of
remote: ! the directory structure.
remote: !
remote: ! If you are trying to deploy a Node.js application, ensure that this
remote: ! file is present at the top level directory. This directory has the
remote: ! following files:
remote: !
remote: ! client/
remote: ! readme.md
remote: ! server/
remote: ! services/
remote: ! wiki/
remote: !
remote: ! If you are trying to deploy an application written in another
remote: ! language, you need to change the list of buildpacks set on your
remote: ! Heroku app using the 'heroku buildpacks' command.
remote: !
remote: ! For more information, refer to the following documentation:
remote: ! https://devcenter.heroku.com/articles/buildpacks
remote: ! https://devcenter.heroku.com/articles/nodejs-support#activation
remote:
remote:
remote: More info: https://devcenter.heroku.com/articles/buildpacks#detection-failure
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to infinite-refuge-86248.
remote:
To https://git.heroku.com/infinite-refuge-86248.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/infinite-refuge-86248.git'
下面的参考是我的服务器 JSON 文件
{
"name": "Infoshot",
"version": "0.0.4",
"description": "Research Tool",
"main": "server.js",
"scripts": {
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm start --prefix ../client/",
"clientinstall": "npm install --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client "
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"config": "^3.2.2",
"dotenv": "^8.2.0",
"enzyme": "^3.11.0",
"express": "^4.17.1",
"express-validator": "^6.2.0",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.7.0",
"nodemailer": "^6.4.14",
"nodemailer-sendgrid": "^1.0.3"
},
"devDependencies": {
"concurrently": "^4.1.2",
"nodemon": "^1.19.2"
}
}
解决方案
尝试将Procfile
以下内容添加到您的根目录:
web: npm client
server: npm start
推荐阅读
- java - Java - 未为 MessagePack 类型定义方法 newDefaultUnpacker(byte[])
- angular - 如何在 Angular 项目中使用 Swal?
- python - 从另一个字典值替换字典值
- php - 需要帮助了解php签名验证
- ruby-on-rails - 将 STI 与 has_many 一起使用会导致活动记录搜索子类表
- php - CakePHP 中的 $this 是什么意思?
- netlogo - 在 Netlogo 中,您可以将列表添加到一起吗?
- firebase - Flutter 上传一批图像并获取所有这些 URL 以存储在 Firestore 中
- python - ndarray 到表(从阶跃函数结果)
- python - 如何将 JSON 转换为格式化的嵌套数组?