You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rails 6.1新项目非默认页面请求报错Webpacker::Manifest::MissingEntryError

Rails 6.1.7.4 Webpacker 编译错误及页面访问异常问题

问题现象

在全新创建的 Rails 6.1.7.4 项目中,访问默认欢迎页(Rails::WelcomeController#index)之外的任意页面(比如Blogs#Index)时,会触发 Webpacker::Manifest::MissingEntryError 错误。

重现步骤

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

环境信息

  • Ruby 2.7.4p191
  • Rails 6.1.7.4
  • Node.js 16.20.2(也曾尝试18和20版本)
  • Yarn 1.22.19
  • macOS Ventura 13.5

编译错误详情

执行 rails webpacker:compile 时出现编译失败错误:

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

Error: Cannot find package '@babel/plugin-proposal-private-methods' imported from /<项目路径>/rails_6-1_app/babel-virtual-resolve-base.js

修改 Babel 配置后的新错误

根据官方建议修改 babel.config.js,替换以下两行插件:

// babel.config.js 
// 替换该行 
// '@babel/plugin-proposal-private-methods',
// 为
'@babel/plugin-transform-private-methods', 

// 同时替换该行
// '@babel/plugin-proposal-private-property-in-object',
// 为
'@babel/plugin-transform-private-property-in-object',

修改后再次执行 rails webpacker:compile,出现新错误:

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 (/<项目路径>/rails_6-1_app/node_modules/webpack/lib/util/createHash.js:135:53)

解决方案

1. 修复 Babel 插件缺失问题

替换插件名称后,还需安装对应的 transform 插件:

yarn add @babel/plugin-transform-private-methods @babel/plugin-transform-private-property-in-object --dev

2. 修复数字信封算法不兼容问题

Node.js 16+ 版本默认禁用了旧的 SSL 哈希算法,可通过以下方式解决:

  • 临时启动服务器:
    NODE_OPTIONS="--openssl-legacy-provider" rails s
    
  • 临时执行编译:
    NODE_OPTIONS="--openssl-legacy-provider" rails webpacker:compile
    
  • 永久配置(适用于 macOS/Linux):
    在 .bashrc、.zshrc 或对应 shell 配置文件中添加:
    export NODE_OPTIONS="--openssl-legacy-provider"
    
    执行 source ~/.zshrc(对应你的shell配置文件)使配置生效。

内容的提问来源于stack exchange,提问作者Neil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 05:37:04