无法在rails中找到javascript运行时,无法在windows上安装'therubyracer'gem

时间:2021-02-09 17:06:47
C:\sites\srhapp>rails generate controller home index
C:/Ruby21/lib/ruby/gems/2.1.0/gems/execjs-2.5.2/lib/execjs/runtimes.rb:48:in `au
todetect': Could not find a JavaScript runtime. See https://github.com/rails/exe
cjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)

This are the error messages i get. kindly help me out .

这是我得到的错误消息。请帮助我。

2 个解决方案

#1


Install nodejs. That may help here.

安装nodejs。这可能对此有所帮助。

Follow this.

#2


Now that you have Nodejs installed, see if any of these can help with the error you are getting (I was going to comment on jon snow's answer, but my suggestions became too long.):

现在您已经安装了Nodejs,看看是否有任何这些可以帮助您获得错误(我将评论jon snow的答案,但我的建议变得太长了。):

  1. Make sure you have C:\Windows\System32 in your system's PATH variable.

    确保系统的PATH变量中有C:\ Windows \ System32。

  2. Close and then restart your command console.

    关闭然后重新启动命令控制台。

  3. Type node -v into the console. Does Nodejs respond?

    在控制台中键入node -v。 Nodejs会响应吗?

  4. Change the therubyracer line in your Gemfile to gem 'therubyracer', {:platforms => [:ruby]}. As far as I know, therubyracer isn't for Windows, but declaring it this way lets it still be used in Heroku if you plan on using that later. Run bundle install after you make this change.

    将Gemfile中的therubyracer行更改为gem'therubyracer',{:platforms => [:ruby]}。据我所知,therubyracer不适用于Windows,但以这种方式声明它仍然可以在Heroku中使用它,如果您打算稍后再使用它。进行此更改后运行bundle install。

Edit

Do you necessarily need Puma in your Windows development environment? If you only need it for deployment on Heroku, the easiest way that I have found to get around its difficulty with Windows is by putting it into the production group along with any other gems Heroku requires.

您是否一定需要在Windows开发环境中使用Puma?如果您只需要在Heroku上进行部署,我发现解决Windows难度的最简单方法是将其与Heroku所需的任何其他宝石一起放入生产组。

Gemfile

...

group( :production ) do
    # Serves static assets in Heroku deployment.
    gem 'rails_12factor'
    # Web server for use with Heroku.
    gem 'puma'
    # Database used by Heroku.
    gem 'pg'
end

...

That way, you can simply exclude those gems when you bundle install in your local development environment.

这样,当您在本地开发环境中捆绑安装时,您可以简单地排除这些宝石。

$ bundle install --without production

If you really do need Puma on a Windows environment, you will have to install OpenSSL libraries and headers (so I have heard; I haven't tried it myself). The comment by luislavena on this page should help you in that case.

如果你真的需要在Windows环境中使用Puma,你必须安装OpenSSL库和标题(所以我听说过;我自己没有尝试过)。在这种情况下,luislavena在此页面上的评论可以帮助您。

#1


Install nodejs. That may help here.

安装nodejs。这可能对此有所帮助。

Follow this.

#2


Now that you have Nodejs installed, see if any of these can help with the error you are getting (I was going to comment on jon snow's answer, but my suggestions became too long.):

现在您已经安装了Nodejs,看看是否有任何这些可以帮助您获得错误(我将评论jon snow的答案,但我的建议变得太长了。):

  1. Make sure you have C:\Windows\System32 in your system's PATH variable.

    确保系统的PATH变量中有C:\ Windows \ System32。

  2. Close and then restart your command console.

    关闭然后重新启动命令控制台。

  3. Type node -v into the console. Does Nodejs respond?

    在控制台中键入node -v。 Nodejs会响应吗?

  4. Change the therubyracer line in your Gemfile to gem 'therubyracer', {:platforms => [:ruby]}. As far as I know, therubyracer isn't for Windows, but declaring it this way lets it still be used in Heroku if you plan on using that later. Run bundle install after you make this change.

    将Gemfile中的therubyracer行更改为gem'therubyracer',{:platforms => [:ruby]}。据我所知,therubyracer不适用于Windows,但以这种方式声明它仍然可以在Heroku中使用它,如果您打算稍后再使用它。进行此更改后运行bundle install。

Edit

Do you necessarily need Puma in your Windows development environment? If you only need it for deployment on Heroku, the easiest way that I have found to get around its difficulty with Windows is by putting it into the production group along with any other gems Heroku requires.

您是否一定需要在Windows开发环境中使用Puma?如果您只需要在Heroku上进行部署,我发现解决Windows难度的最简单方法是将其与Heroku所需的任何其他宝石一起放入生产组。

Gemfile

...

group( :production ) do
    # Serves static assets in Heroku deployment.
    gem 'rails_12factor'
    # Web server for use with Heroku.
    gem 'puma'
    # Database used by Heroku.
    gem 'pg'
end

...

That way, you can simply exclude those gems when you bundle install in your local development environment.

这样,当您在本地开发环境中捆绑安装时,您可以简单地排除这些宝石。

$ bundle install --without production

If you really do need Puma on a Windows environment, you will have to install OpenSSL libraries and headers (so I have heard; I haven't tried it myself). The comment by luislavena on this page should help you in that case.

如果你真的需要在Windows环境中使用Puma,你必须安装OpenSSL库和标题(所以我听说过;我自己没有尝试过)。在这种情况下,luislavena在此页面上的评论可以帮助您。