LoginSignup
1
0

More than 1 year has passed since last update.

Heroku で デプロイ エラー (~version not specified in package.json)

Posted at

開発環境

対象 バージョン

対象 version
Node.js v15.4.0
npm 7.0.15

発生している問題・エラー

作成途中だったアプリを一時中断して、Nuxt.jsの学習をしていた。
久しぶりに途中だったアプリをgit push heroku mainをしたら、下記のエラーが出るようになってしまった。
どうやら、Node version not specified in package.jsonという部分が問題のようだった。
これは、Nodeのバージョンがpackage.jsonに記述されていないことらしい。
以前は普通にデプロイ出来てたのに、なぜこうなってしまったかは分からなかった。

デプロイログ.
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:        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: 2e1b37e888e9ad2a5e50da16618bf37879e28f8a
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version 2e1b37e888e9ad2a5e50da16618bf37879e28f8a
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 .
remote: 
To https://git.heroku.com/~.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/~.git'

解決手順

(https://devcenter.heroku.com/articles/troubleshooting-node-deploys) の「Other Available Runtimes」 を参考にして
package.jsonに"engines": {~}を加えて、mainブランチにpushしたら解決できた。
今回の場合は、node.jsにエラーメッセージが出てたので、"node": "15.4.0" を加えた。

package.json
{
  "name": "example-app",
  "description": "a really cool app",
  "version": "1.0.0",
  "engines": {
    "node": "15.4.0"
  }
}

参考記事

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0