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

Ruby on Rails引入SCSS失败:使用Bootstrap Gem启动报错求助

Fixing ExecJS::ProgramError with Bootstrap in Rails 5.2

Hey there, let's work through this ExecJS error you're facing when trying to use Bootstrap in your Rails app. That identifier '(function(opts, pluginOpts) {return eval(process' undefined error is usually tied to issues with the JavaScript runtime ExecJS relies on, or small hiccups in your asset pipeline setup. Here's how to fix it step by step:

1. Check your Node.js version (most common fix)

ExecJS uses your system's Node.js to process JavaScript assets, and Ruby 2.4.x + Rails 5.2 don't play nice with newer Node.js versions (16+).

  • Run node -v in your terminal to check your current version.
  • If it's 16 or higher, downgrade to a compatible version like Node.js 14.x (LTS). You can use a version manager like nvm to switch versions easily:
    nvm install 14
    nvm use 14
    

2. Clean up your asset pipeline cache

Stale cached assets can cause weird errors like this. Run these commands to clear and rebuild your assets:

rails assets:clobber
rails assets:precompile # Skip this in development if you use live asset compilation

3. Verify your Bootstrap import setup

Double-check your application.scss file to make sure there's no invalid syntax messing things up:

  • Ensure the file is named application.scss (not .css) so Rails processes it as SCSS.
  • The @import "bootstrap"; line should be placed after any comment blocks (like you have), but make sure there are no stray characters or invalid SCSS before it that could break the import.

4. Fall back to therubyracer (if Node.js fixes don't work)

If adjusting Node.js doesn't resolve the issue, you can replace ExecJS's default runtime with the V8 engine via the therubyracer gem:

  • Add this line to your Gemfile:
    gem 'therubyracer', platforms: :ruby
    
  • Run bundle install to install it, then restart your Rails server.

Quick checks on your existing code

Looking at your files:

  • Your guest.erb layout is correctly linking to the application stylesheet—no issues there.
  • Your Gemfile has all the right dependencies (sass-rails, bootstrap 4.1.1 is fully compatible with Rails 5.2) so that's good to go.

Try these steps in order, and your Bootstrap styles should load without that ExecJS error soon!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 07:09:35