英文:
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
中的spring
和spring-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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论