# DEV：无法加载此文件 -- omniauth/strategies/oauth2 (LoadError)

**URL:** https://meta.discourse.org/t/dev-cannot-load-such-file-omniauth-strategies-oauth2-loaderror/161259
**Category:** Development
**Created:** [2020年八月18日 10:56 UTC](https://meta.discourse.org/t/dev-cannot-load-such-file-omniauth-strategies-oauth2-loaderror/161259 "2020-08-18T10:56:52Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![DBHacker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dbhacker/32/173072_2.png) [@DBHacker](https://meta.discourse.org/u/DBHacker)
#### Post date: [2020年八月18日 10:56 UTC](https://meta.discourse.org/t/dev-cannot-load-such-file-omniauth-strategies-oauth2-loaderror/161259/1 "2020-08-18T10:56:52Z")

</div>

突然，在 Mac 上的 Discourse 开发环境中执行 git pull 后，尽管 `bundle install` 已成功，但在尝试运行任何 rake 或 rails 命令时出现了以下错误：

```plaintext
gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `require': cannot load such file -- omniauth/strategies/oauth2 (LoadError)

```

我已尝试移除所有 gem、重新开始、从头重新安装，但均无济于事；始终出现相同的错误。

我能否在开发环境中直接禁用这个 oauth2 功能？

以下操作正常：

```plaintext
cd ./discourse
bundle install

```

但当我尝试例如：

```plaintext
$ bundle exec rake db:create
rake aborted!
LoadError: cannot load such file -- omniauth/strategies/oauth2

```

这种情况已经持续了一整晚，让我彻夜未眠！

请告诉我如何绕过这个今天突然出现的障碍。

---

<div class="post-metadata">

### Author: ![neounix](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neounix/32/215617_2.png) [@neounix](https://meta.discourse.org/u/neounix)
#### Post date: [2020年八月18日 13:28 UTC](https://meta.discourse.org/t/dev-cannot-load-such-file-omniauth-strategies-oauth2-loaderror/161259/2 "2020-08-18T13:28:11Z")

</div>

嘿 @DBHacker

很遗憾听到你在 macOS 上进行开发时遇到了问题。这确实很棘手。

为了帮你，我登录了一台从未安装过 Rails（或 Discourse）的 Mac mini。那是一台全新的 macOS 系统，我只用它做文件服务器。

我完全从零开始按照 macOS 开发环境安装指南操作；期间遇到了目录权限等常见问题，以及那个似乎总是很麻烦的 ` cppjieba_rb` gem；但它最终成功安装了，结果如下：

 ![Image 8-18-20 at 8.19 PM](https://global.discourse-cdn.com/meta/original/3X/7/c/7c89ddd84dcbafe85e202dd2ae83c95c39a4427a.jpeg)

所以，@DBHacker，看起来你的开发环境存在某些损坏，因为我今天可以在一台全新的 Mac 上从零开始成功安装。

希望这能作为一个额外的参考点，对你有所帮助。

……现在，我又在一台 Mac mini 上搭建好了一个可用的 Discourse 开发环境 😉

祝你好运，祝你早日让一切重新运行起来！

---

<div class="post-metadata">

### Author: ![DBHacker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dbhacker/32/173072_2.png) [@DBHacker](https://meta.discourse.org/u/DBHacker)
#### Post date: [2020年八月19日 03:19 UTC](https://meta.discourse.org/t/dev-cannot-load-such-file-omniauth-strategies-oauth2-loaderror/161259/3 "2020-08-19T03:19:51Z")

</div>

哇，@neounix 太棒了！

感谢您抽出宝贵的时间帮忙！

这台 Mac 早已不是全新状态。在读了您的回复后，我不知疲倦地尝试用 Ruby 2.7.1、2.6.1 和 2.6.5 从“零”开始重新安装，但每次都遇到了与 `bootsnap` 相关的不同错误。

简单的 Rails 应用生成后运行正常；Discourse 的 bundle 也能正常工作；但每当我启动 Rails 时，就会不断收到 `bootsnap` 错误。

我本来打算彻底清除 Ruby 和 Rails，从零开始重新搭建，但因为还有其他正在进行的 Rails 项目，所以暂时把学习和折腾 Discourse 插件的事情放一放。

再次感谢 @neounix 抽出时间帮助我，并向我展示了在纯净机器上它是如何正常工作的。

---

<div class="post-metadata">

### Author: ![neounix](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neounix/32/215617_2.png) [@neounix](https://meta.discourse.org/u/neounix)
#### Post date: [2020年八月19日 03:59 UTC](https://meta.discourse.org/t/dev-cannot-load-such-file-omniauth-strategies-oauth2-loaderror/161259/4 "2020-08-19T03:59:06Z")

</div>

别担心。我很高兴在一个文件服务器上搭建了另一个 Discourse 开发环境 🙂

很高兴能在某些方面帮到你。

 ![Screen Shot 2020-08-19 at 12.01.24 PM](https://global.discourse-cdn.com/meta/original/3X/b/5/b5e5b2e1960db50741fcb3bf5993b6311fab4685.png)

---

<div class="post-metadata">

### Author: ![DBHacker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dbhacker/32/173072_2.png) [@DBHacker](https://meta.discourse.org/u/DBHacker)
#### Post date: [2020年八月19日 05:38 UTC](https://meta.discourse.org/t/dev-cannot-load-such-file-omniauth-strategies-oauth2-loaderror/161259/5 "2020-08-19T05:38:31Z")

</div>

> [@neounix](#):
>
> 很高兴能帮上一点忙。

谢谢你分享你的版本截图 @neounix 🥰

由于 macOS 开发安装脚本因某种原因未能正确升级或安装（我猜可能是因为之前的安装不是全新的，而旧的版本，但我不确定；不过我多次运行了该脚本，左试右试）；我手动使用 `rvm` 升级了 Ruby（参考此指南）：

[https://medium.com/@IanRahman/how-to-upgrade-ruby-on-a-mac-a592c6085c63](https://medium.com/@IanRahman/how-to-upgrade-ruby-on-a-mac-a592c6085c63)

然后手动将 Rails gem 更新到 `6.0.3.2` 版本；并在 `./discourse` 目录下再次运行了 `bundle`：

 ![](https://media.tenor.com/videos/0267ab2e9af638b9e7a6252a02a30ae6/mp4)

 ![Screen Shot 2020-08-19 at 12.27.44 PM](https://global.discourse-cdn.com/meta/original/3X/2/4/24d5e72be89fc13db1a3b7ee6f14d0210955d0cd.jpeg)

非常感谢！！！！！🥰
