2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Heroku】デプロイエラー Cannot find package '@babel/plugin-proposal-private-methods' 解決策を探る

Posted at

プログラミング初心者です。
Herokuへのデプロイで詰まった部分を、勉強のためまとめてみようと思います。

環境

Ruby on Rails (6.1.7.6)
Heroku (7.47.7)
MySQL(8.1.0)

エラー内容

heroku.logs

 Compiling...
       Compilation failed:
       Hash: 0995169381fdf04c2e5d
       Version: webpack 4.47.0
       Time: 598ms
       Built at: 09/19/2023 9:01:59 AM
        2 assets
       Entrypoint application = js/application-d6bd20caf583a9f90502.js js/application-d6bd20caf583a9f90502.js.map
       [0] ./app/javascript/packs/application.js 4.54 KiB {0} [built] [failed] [1 error]
       
       ERROR in ./app/javascript/packs/application.js
       Module build failed (from ./node_modules/babel-loader/lib/index.js):
       Error: Cannot find package '@babel/plugin-proposal-private-methods' imported from /tmp/build_ac3acc7b/babel-virtual-resolve-base.js

注目したのは、Error: Cannot find package '@babel/plugin-proposal-private-methods'の部分。
@babel/plugin-proposal-private-methodsが見つかりませんということらしい。

解決方法

herokuスターターガイドの「babelのリグレッションの修正」を参考にコードを修正。rails6とbabelの相性が、元のままだと悪いらしい。具体的には、proposal部分をtransformへ変更した。

babel.config.js (修正前).
@babel/plugin-proposal-private-methods
@babel/plugin-proposal-private-property-in-object
babel.config.js (修正後).
@babel/plugin-transform-private-methods
@babel/plugin-transform-private-property-in-object

デプロイ、学んだこと

git add . 
git commit -m "fix babel error"
git push heroku master

変更点をコミットして、herokuにプッシュ。エラーは解消され、無事にデプロイできた。
今回学んだことは、きちんとlogなどでエラー文を読み、公式マニュアルを読むこと。それが一番の近道だった。

参考にした記事

2
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?