简体   繁体   English

无法启动 reactJS 服务器 | 错误:“rbenv:纱线:找不到命令”

[英]Cannot start reactJS server | error: "rbenv: yarn: command not found"

I have recently installed rbenv for some ruby projects but now cannot run my reactjs server for a different project.我最近为一些 ruby 项目安装了 rbenv,但现在无法为另一个项目运行我的 reactjs 服务器。

The error message from running yarn start is rbenv: yarn: command not found运行yarn start的错误消息是rbenv: yarn: command not found

According to this link the error may have something to do with the shims.根据此链接,该错误可能与垫片有关。 So I ran the below code in the terminal:所以我在终端中运行了以下代码:

for ver in $(rbenv whence yarn); do
  RBENV_VERSION="$ver" gem uninstall -ax yarn
  rm -f "$(rbenv prefix "$ver")/bin/yarn"
done
rbenv rehash

# now check the yarn executable again:
which -a yarn

when running which -a yarn I get:当运行which -a yarn我得到:

/home/user/.rbenv/shims/yarn
/home/user/.rbenv/shims/yarn
/home/user/.nvm/versions/node/v14.8.0/bin/yarn
/home/user/.rbenv/shims/yarn
/home/user/.rbenv/shims/yarn
/usr/bin/yarn
/bin/yarn

Clearly I'm missing something here显然我在这里遗漏了一些东西

That code from the thread that you linked to will remove the yarn shim from any versions of Ruby that you may have installed with rbenv that have it.您链接到的线程中的该代码将从您可能已使用具有它的 rbenv 安装的 Ruby 的任何版本中删除纱线垫片。 However, some versions of Rails (maybe other Ruby projects too?) also have a yarn shim inside their bin/ directory.但是,某些版本的 Rails(可能还有其他 Ruby 项目?)在它们的bin/目录中也有一个 yarn shim。 The presence of this shim causes a yarn shim to be added to ~/rbenv/shims/ each time rbenv rehash is called to regenerate your binstubs.每次调用rbenv rehash以重新生成 binstub 时,此 shim 的存在会导致将纱线 shim 添加到~/rbenv/shims/中。 The rbenv rehash command can be called automatically each time your shell environment is loaded too if your environment was setup with rbenv to do this with eval "$(rbenv init -)" . rbenv rehash命令可以在每次加载 shell 环境时自动调用,如果您的环境使用 rbenv 设置以使用eval "$(rbenv init -)"执行此操作。 The shim inside ~/rbenv/shims/ is what causes this rbenv: yarn: command not found error globally whenever you invoke yarn. ~/rbenv/shims/中的 shim 是导致这个rbenv: yarn: command not found错误的原因,无论何时你调用 yarn。

If you move the shim inside your project from bin/ to .bundle/bin/ , then run rbenv rehash , that should fix the issue.如果将项目中的 shim 从bin/移动到.bundle/bin/ ,然后运行rbenv rehash ,应该可以解决问题。 If you have yarn installed globally then you could also consider removing the shim from your project altogether, since all it does is call yarn for you and give you an error if it's not installed.如果您在全局范围内安装了 yarn,那么您还可以考虑完全从项目中删除 shim,因为它所做的只是为您调用 yarn,如果未安装,则会给您一个错误。

Besides uninstalling the yarn gem from all your rbenv versions, you also need to change the binstubs paths for all your rails projects (and any other rbenv-managed project using bundler).除了从所有 rbenv 版本中卸载yarn gem 之外,您还需要更改所有 rails 项目(以及任何其他使用 bundler 的 rbenv 管理的项目)的 binstubs 路径。

First, run this to see which projects rbenv-binstubs is looking for shimmable executables: cat "$(rbenv root)/bundles"首先,运行此命令以查看rbenv-binstubs正在寻找 shimmable 可执行文件的项目: cat "$(rbenv root)/bundles"

cd into each of those directories and run bundle install --binstubs.bundle/bin to set the binstubs path. cd进入每个目录并运行bundle install --binstubs.bundle/bin以设置 binstubs 路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM