-2

On a brand new rails 6.1.7.4 app, I'm getting the following error when making a request to any page besides the default "Rails::WelcomeController#index" screen:

Webpacker::Manifest::MissingEntryError in Blogs#Index

Error Message

Reproduction steps:

rails new rails_6-1_app
cd rails_6-1_app
rails g scaffold blog title
rails db:migrate
rails s
# Make request to http://localhost:3000/blogs/

Environment:

  • Ruby 2.7.4p191
  • Rails 6.1.7.4
  • node 16.20.2 (but node versions 18 and 20 were attempted as well)
  • yarn 1.22.19
  • macOS Ventura 13.5

Webpacker:compile error

I notice that when I attempt rails webpacker:compile I get more information on what is going on:

Compiling...
Compilation failed:
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: Cannot find package '@babel/plugin-proposal-private-methods' imported from /<Path-TO-MY-APP>/rails_6-1_app/babel-virtual-resolve-base.js

It was suggested via this rails issue to modify two lines within the default, generated babel.config.js file:

// babel.config.js 
// replace this line 
// '@babel/plugin-proposal-private-methods',
// with this line
'@babel/plugin-transform-private-methods', 

// also replace this line
// '@babel/plugin-proposal-private-property-in-object',
// with this line
'@babel/plugin-transform-private-property-in-object',

However, making that change and then running rails webpacker:compile generates a new error:

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:69:19)
    at Object.createHash (node:crypto:133:10)
    at module.exports (/<Path-To-My-App>/rails_6-1_app/node_modules/webpack/lib/util/createHash.js:135:53)
Neil
  • 4,578
  • 14
  • 70
  • 155
  • 1
    You are most likely missing Node modules. You need to run `rails webpacker:install`. If that works then it's a duplicate question to this one: https://stackoverflow.com/questions/54113179/rails-webpackermanifestmissingentryerror-in-homeindex – Casper Aug 17 '23 at 18:53
  • @Casper unfortunately that did not resolve it for me. – Neil Aug 17 '23 at 18:56
  • There is currently an open issue that appears to be relevant. Unfortunately the proposed solution in that thread didn't work for me either: https://github.com/rails/rails/issues/48372 – Neil Aug 17 '23 at 18:59
  • I *strongly* recommend migrating to https://github.com/shakacode/shakapacker – kwerle Aug 17 '23 at 19:35

2 Answers2

2

Same error is issued here:

https://github.com/rails/rails/issues/48372

Description:

This appears to be happening because webpacker generates a babel.config.js that includes plugin-proposal-private-methods. However it does not add a dependency to plugin-proposal-private-methods. Instead, it depends on a package that depends on plugin-proposal-private-methods.

Recently that package was re-named to plugin-transform-private-methods babel/babel#15614 and probably it was released babel/babel@389ecb0.

So now when babel tries to execute it reads in the babel.config.js file, sees that it needs plugin-proposal-private-methods. Tries to load it, but that fails because plugin-proposal-private-methods is not installed (since it is no longer a dependency).

Solution:

You can replace the name in your babel.config.js from proposal to transform:

// '@babel/plugin-proposal-private-methods',
'@babel/plugin-transform-private-methods', 

// '@babel/plugin-proposal-private-property-in-object',
'@babel/plugin-transform-private-property-in-object',

// etc.
mechnicov
  • 12,025
  • 4
  • 33
  • 56
  • 1
    This solution for me generates a new error when I run `rails webpacker:compile`: `Error: error:0308010C:digital envelope routines::unsupported`. – Neil Aug 18 '23 at 12:56
  • Did you check it? https://stackoverflow.com/q/69692842/10608621 – mechnicov Aug 21 '23 at 23:34
1

This answer functions as a work around: I simply disabled webpacker and reverted back to using sprockets. You apparently don't have to use webpacker at all. I used this SO post as a reference to configure a new rails 6.1 app to use sprockets.

Reproduction steps

First create the app but without webpacker:

rails new rails_6-1_app --skip-webpack-install
cd rails_6-1_app
rails g scaffold blog title
rails db:migrate

Within Gemfile, comment out gem 'webpacker', '~> 5.0' and then add the following gems:

# Gemfile
# comment out webpacker
# gem 'webpacker', '~> 5.0'
gem 'sprockets', '~> 4'
gem 'sprockets-rails', :require => 'sprockets/railtie'

Update app/assets/config/manifest.js so it looks like this:

//= link_tree ../images
//= link application.js
//= link application.css

Add the file app/assets/javascripts/application.js with this:

//= require rails-ujs
//= require turbolinks
//= require_tree .

Within app/views/layouts/application.html.erb, replace javascript_pack_tag with javascript_include_tag.


Run bundle install

Now when I boot the server up with rails s and make a request to the app via http://localhost:3000/blogs, it works.

blogs index screen

Note that this was merely tested in development mode and not in production mode, and I did not test with any assets (images, additional css, bootstrap, custom javascript, etc).

Neil
  • 4,578
  • 14
  • 70
  • 155