You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

全新Rails项目报错:ExecJS::ProgramError in Posts#index求助

Fixing ExecJS::ProgramError (TypeError) on Windows Rails Setup

Hey there, let's get this sorted out. That ExecJS::ProgramError pointing to your application.html.erb line 7 is almost always a JavaScript runtime issue specific to Windows. Here's what's going on and how to fix it:

The Root Cause

Rails uses ExecJS to run JavaScript code during asset compilation. On Windows, the default runtime is JScript—the ancient JavaScript engine built into Windows—which doesn't support modern JavaScript syntax used by Rails assets (like Turbolinks or parts of the asset pipeline). When it hits that unsupported code, it throws the "Object doesn't support this property or method" error.

Node.js provides a modern, reliable JavaScript runtime that Rails will automatically detect and use. Here's how to set it up:

  • Grab the latest LTS version of Node.js from its official site (make sure to check the "Add to PATH" option during installation—this is crucial).
  • Restart your command prompt or terminal, then verify it's installed by running node -v—you should see a version number pop up if it worked.
  • Restart your Rails server with rails s and refresh the Posts#index page. This should resolve the error immediately.

Solution 2: Use therubyracer Gem (Alternative, Less Ideal)

If you don't want to install Node.js, you can use a Ruby-based V8 engine wrapper as a fallback:

  • Open your Gemfile and add this line:
    gem 'therubyracer', platforms: :ruby
    
  • Run bundle install to install the gem. Note: This might have installation hiccups on newer Windows versions, so Node.js is the safer, more maintainable bet.
  • Restart your Rails server and test the page again.

Even though it looks like a stylesheet issue, Rails' asset pipeline processes JavaScript and CSS together when you use stylesheet_link_tag with data-turbolinks-track. The error actually stems from ExecJS trying to parse modern JS code (like Turbolinks) with the outdated JScript engine.

内容的提问来源于stack exchange,提问作者addysplendor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:41:06