与执行Rails命令相关的Spring错误

huangapple go评论119阅读模式
英文:

Error related with spring when trying to execute rails commands

问题

我已经创建了一个新的Rails应用程序文件夹,一切都运行顺利。一旦进入这样的文件夹,运行任何类型的Rails命令,比如rails s,将会提示我:

您尝试在Spring已加载时调用它(即Spring常量已定义)。

这可能是因为您使用Spring 1.0生成了二进制文件,并且现在您的系统上有一个Spring版本大于1.0。要解决此问题,请将您的bundle升级到最新的Spring版本,然后运行`bundle exec spring binstub --all`以重新生成您的二进制文件。这是从1.0升级到1.1所必需的一次性步骤。

我目前的版本是

spring -v
Spring版本为2.1.0

我尝试了以下操作,但得到了相同的结果。我还尝试了卸载Spring并重新安装。

bundle exec spring binstub --all
* bin/rake: Spring已经存在
* bin/rails: Spring已经存在
英文:

I have created a new rails application folder, which worked smoothly. Once within such folder, running any kind of rails command like rails s will prompt me:

You've tried to invoke Spring when it's already loaded (i.e. the Spring constant is defined).

This is probably because you generated binstubs with Spring 1.0, and you now have a Spring version > 1.0 on your system. To solve this, upgrade your bundle to the latest Spring version and then run `bundle exec spring binstub --all` to regenerate your binstubs. This is a one-time step necessary to upgrade from 1.0 to 1.1.

I currently have

spring -v
Spring version 2.1.0

I've tried the following, getting the same results. I also tried uninstalling spring and reinstalling.

 bundle exec spring binstub --all
* bin/rake: Spring already present
* bin/rails: Spring already present

答案1

得分: 9

这是一个回答,经过尝试了所有其他相关解决方案后才找到这个隐藏在评论中的答案。希望它能帮助将来的某个人。

至于原因,我在我的一侧唯一看到的原因是从ubuntu (pop os) 20.04升级到20.10。在我两次编码会话之间没有做任何其他操作。

我尝试了那篇帖子中的指示,但一直不起作用。不知何故,运行gem pristine --all解决了这个问题,但不确定原因 - Gotey Jan 3 at 14:05

英文:

Posting this as an answer after trying every other related solutions to finally find this hidden in a comment. Hope it helps someone in the future.

As for the why, the only reason I see on my side is upgrading from ubuntu (pop os) 20.04 to 20.10. Didn't do anything else between my two coding sessions.

> I've tried the indications in that post and kept not working. Somehow
> running gem pristine --all solves the issue, but not sure why –
> Gotey Jan 3 at 14:05

答案2

得分: 1

当您在代码中require了未安装的内容时,可能会发生这种情况。

例如,当我导入sentry-ruby但未安装实际的 gem 时,我遇到了这个问题。检查您的依赖项和导入。

英文:

It may happen when you've require something in your code which is not installed.

For instance, I've encountered this issue when I was imported sentry-ruby without installing actual gem. Check your dependencies and imports.

答案3

得分: 0

我移除了Gemfile中的springspring-watcher-listen两个宝石,然后通过bundle exec gem uninstall gemname命令卸载了这两个宝石。尝试运行rails s时,我遇到了一个关于MySQL的新错误。最终在修复了这些错误后,我成功地运行了rails s。然后,我重新添加了这两个宝石,运行了bundle,之后没有出现错误。

英文:

For me, I removed the spring and spring-watcher-listen gems from the Gemfile and then uninstalled these 2 gems via the bundle exec gem uninstall gemname command.

I then discovered a new error when trying to run rails s which was about MySQL. Finally after fixing those errors I was able to do a successful rails s. I then added back the 2 gems, ran bundle and had no errors afterwards.

huangapple
  • 本文由 发表于 2020年1月3日 21:41:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/59579627.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定