我无法在Heroku上部署我的应用程序,每次我试图将代码推送到Heroku时都会收到以下错误。
首先,我使用命令heroku create
创建了我的Heroku应用程序。然后,我将所有修改后的文件添加并提交到git暂存区,最后,当我试图使用git推送到Heroku时,它在后构建部分失败了。
我用于推送代码的命令:git push heroku master
我得到的错误:
remote: -----> Build
remote: Running heroku-postbuild
remote:
remote: > dev-community-starter@1.0.0 heroku-postbuild /tmp/build_d493d086
remote: > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
remote:
remote:
remote: > core-js@2.6.12 postinstall /tmp/build_d493d086/client/node_modules/babel-runtime/node_modules/core-js
remote: > node -e "try{require('./postinstall')}catch(e){}"
remote:
remote:
remote: > core-js@3.8.1 postinstall /tmp/build_d493d086/client/node_modules/core-js
remote: > node -e "try{require('./postinstall')}catch(e){}"
remote:
remote:
remote: > core-js-pure@3.8.1 postinstall /tmp/build_d493d086/client/node_modules/core-js-pure
remote: > node -e "try{require('./postinstall')}catch(e){}"
remote:
remote:
remote: > ejs@2.7.4 postinstall /tmp/build_d493d086/client/node_modules/ejs
remote: > node ./postinstall.js
remote:
remote: added 1937 packages from 730 contributors and audited 1942 packages in 48.194s
remote:
remote: 123 packages are looking for funding
remote: run `npm fund` for details
remote:
remote: found 5928 vulnerabilities (209 moderate, 5719 high)
remote: run `npm audit fix` to fix them, or `npm audit` for details
remote:
remote: > client@0.1.0 build /tmp/build_d493d086/client
remote: > react-scripts build
remote:
remote: Creating an optimized production build...
remote: Browserslist: caniuse-lite is outdated. Please run:
remote: npx browserslist@latest --update-db
remote:
remote: Why you should do it regularly:
remote: https://github.com/browserslist/browserslist#browsers-data-updating
remote: Failed to compile.
remote:
remote: ./src/utils/api.js
remote: Cannot find module: 'axios'. Make sure this package is installed.
remote:
remote: You can install this package by running: yarn add axios.
remote:
remote:
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! client@0.1.0 build: `react-scripts build`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the client@0.1.0 build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.DNuM9/_logs/2021-06-24T11_06_31_565Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! dev-community-starter@1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the dev-community-starter@1.0.0 heroku-postbuild script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.DNuM9/_logs/2021-06-24T11_06_31_594Z-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: Some possible problems:
remote:
remote: - Node version not specified in package.json
remote: https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
remote:
remote: - A module may be missing from 'dependencies' in package.json
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys#ensure-you-aren-t-relying-on-untracked-dependencies
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: b76c1f2afa5b943b747dc113ff0dc1004c044030
remote: !
remote: ! We have detected that you have triggered a build from source code with version b76c1f2afa5b943b747dc113ff0dc1004c044030
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 intense-reef-14591.
remote:
To https://git.heroku.com/intense-reef-14591.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/intense-reef-14591.git'
有人能指导我如何解决这个错误吗?
我猜你已经检查了以下问题,对吧?
remote: Some possible problems:
remote:
remote: - Node version not specified in package.json
remote: https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
remote:
remote: - A module may be missing from 'dependencies' in package.json
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys#ensure-you-aren-t-relying-on-untracked-dependencies
您也可以尝试不在推送中包含node_modules
文件夹。
也尝试通过heroku网络和github回购来推动它
根据错误日志,axios
包未作为依赖项安装在package.json
中。
您可能已经在设备上全局安装了Axios,因此它将在本地工作,但在Heroku部署过程中,它无法找到这种依赖关系。
因此,通过运行以下命令安装它:
npm install axios
然后再试一次。如果同样的问题仍然存在,请共享您的package.json
文件。