gpt4 book ai didi

javascript - Node.js:无法将 node.js 应用程序部署到 heroku

转载 作者:行者123 更新时间:2023-12-05 05:59:48 24 4
gpt4 key购买 nike

我正在尝试将我的 node.js 应用程序部署到 heroku。我做了所有必要的事情,但我遇到了这样的错误。

remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/nodejs
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NODE_VERBOSE=false
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): 16.3.0
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version 16.3.0...
remote: Downloading and installing node 16.3.0...
remote: Using default npm version: 7.15.1
remote:
remote: -----> Installing dependencies
remote: Installing node modules
remote: npm ERR! code E404
remote: npm ERR! 404 Not Found - GET https://registry.npmjs.org/har-validator/-/har-validator-5.1.2.tgz - Not found
remote: npm ERR! 404
remote: npm ERR! 404 'har-validator@https://registry.npmjs.org/har-validator/-/har-validator-5.1.2.tgz' is not in the npm registry.
remote: npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
remote: npm ERR! 404
remote: npm ERR! 404 Note that you can also install from a
remote: npm ERR! 404 tarball, folder, http url, or git url.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.7maaf/_logs/2021-06-13T18_35_23_460Z-debug.log
remote:
remote: -----> Build failed
remote:
remote: We're sorry this build is failing! You can troubleshoot common issues here:
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote: If you're stuck, please submit a ticket so we can help:
remote: https://help.heroku.com/
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: !
remote: ! ## Warning - The same version of this code has already been built: 944efd5ebf13ff49831d29f02a9a1f6565355373
remote: !
remote: ! We have detected that you have triggered a build from source code with version 944efd5ebf13ff49831d29f02a9a1f6565355373
remote: ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote: !
remote: ! If you are developing on a branch and deploying via git you must run:
remote: !
remote: ! git push heroku <branchname>:main
remote: !
remote: ! This article goes into details on the behavior:
remote: ! https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: ! Push rejected to stark-lowlands-47617.
remote:
To https://git.heroku.com/stark-lowlands-47617.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/stark-lowlands-47617.git'

我试着这样做:

git push heroku master:main

这是我的 package.json:

{
"name": "languagelearningapp",
"engines" : { "node" : "16.3.0" },
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"basic-auth": "^2.0.1",
"bcrypt": "^3.0.2",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",
"callback": "0.0.1",
"express": "^4.16.4",
"fcm-node": "^1.3.0",
"fcm-notification": "^2.0.0",
"firebase-admin": "^6.2.0",
"jsonwebtoken": "^8.3.0",
"mysql": "^2.16.0",
"nodemon": "^1.18.5",
"sendotp": "^1.2.9"
}
}

但这并没有帮助。我还尝试将 Node 模块添加到 .gitignore,但没有成功。特别是,我尝试切换到不同的分支,但效果不佳。

请帮助我。

最佳答案

在我看来,您需要在本地机器上降级 nodeLTS 版本(为此使用 nvm ),然后基本上重新配置您的项目以使用 LTS 版本:删除 package.jsonpackage-lock.json,删除node_modules 文件夹,然后运行 ​​npm init 并安装您正在使用的依赖项,例如 bcrypt 等 ..

之后,您需要编辑新的 package.json 并通过添加以下代码告诉 heroku 使用 LTS 版本:

"engines": {
"node": "14.x"
},

你的 package.json 应该看起来像这样:

{
"name": "languagelearningapp",
"engines" : { "node" : "14.x" },
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"author": "",
"license": "ISC",
"dependencies": {
// your project dependencies
}
}

我知道我稍后会回来解决这个问题,但如果遇到同样的问题,我会首先尝试这样做。

关于javascript - Node.js:无法将 node.js 应用程序部署到 heroku,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67961767/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com