在一个全新的rails 6.1.7.4
应用程序上,当我向除了默认的“Rails::WelcomeController#index”屏幕之外的任何页面发出请求时,都会收到以下错误:
Webpacker::Manifest::MissingEntryError in Blogs#Index
复制步骤:
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/
环境:
- Ruby 2.7.4p191
- Rails 6.1.7.4
- 节点16.20.2(但也尝试了节点版本18和20)
- Yarn1.22.19
- macOS Ventura 13.5
Webpacker:编译错误
我注意到,当我尝试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 /<Path-TO-MY-APP>/rails_6-1_app/babel-virtual-resolve-base.js
建议via this rails issue修改默认生成的babel.config.js文件中的两行:
// 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',
但是,进行该更改并运行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 (/<Path-To-My-App>/rails_6-1_app/node_modules/webpack/lib/util/createHash.js:135:53)
2条答案
按热度按时间utugiqy61#
在此处发布相同的错误:
https://github.com/rails/rails/issues/48372
说明:
这似乎是因为webpacker生成了一个包含
plugin-proposal-private-methods
的babel.config.js
。但是,它不会向plugin-proposal-private-methods
添加依赖项。相反,它依赖于一个依赖于plugin-proposal-private-methods
的包。最近,这个包被重新命名为
plugin-transform-private-methods
babel/babel#15614,可能是发布了babel/babel@389ecb0。所以现在当babel尝试执行时,它读取
babel.config.js
文件,看到它需要plugin-proposal-private-methods
。尝试加载它,但失败了,因为plugin-proposal-private-methods
没有安装(因为它不再是依赖项)。解决方案:
您可以将
babel.config.js
中的名称从proposal
替换为transform
:r1wp621o2#
此答案可作为解决方案:我只是禁用了webpacker并恢复使用链轮。显然你根本不需要使用webpacker。我使用this SO post as a reference配置了一个新的rails
6.1
应用程序来使用链轮。复制步骤
首先创建应用程序,但不使用webpacker:
在
Gemfile
中,注解掉gem 'webpacker', '~> 5.0'
,然后添加以下gem:更新app/assets/config/manifest.js,使其看起来像这样:
添加文件app/assets/javascripts/application.js如下:
在app/views/layouts/application.html.erb中,将
javascript_pack_tag
替换为javascript_include_tag
。运行
bundle install
现在,当我用
rails s
Boot 服务器并通过http://localhost:3000/blogs
向应用程序发出请求时,它可以正常工作。请注意,这只是在开发模式下测试,而不是在生产模式下测试,我没有使用任何资产(图像,附加css,bootstrap,自定义JavaScript等)进行测试。