Rails 5.1.6资产加载报错求助:Errno::ENOENT文件不存在
Hey there, that ExecJS temp file error is super frustrating—let's break down what's going on and fix it. This issue usually pops up on Windows because the default ExecJS runtime (JScript, Windows' built-in JS engine) has trouble cleaning up temporary files, either due to permission locks or naming conflicts. Here are a few reliable solutions:
1. Switch to Node.js as your ExecJS runtime (most recommended)
The easiest long-term fix is to use Node.js instead of the default Windows JScript. It's more stable for Rails asset compilation:
- Download and install the latest LTS version of Node.js (make sure to check "Add to PATH" during installation)
- Restart your command prompt/terminal and Rails server so the system picks up Node's path
- ExecJS will automatically detect Node and use it instead, bypassing the temp file cleanup issues entirely
2. Modify ExecJS temp file naming (no extra software needed)
If you don't want to install Node, you can tweak how ExecJS names its temp files to avoid conflicts. Create an initializer file in your Rails project:
- Create
config/initializers/execjs.rb - Paste this code into the file:
module ExecJS module Runtime class JScript def tempfile_name File.join(Dir.tmpdir, "execjs.#{$$}.#{Thread.current.object_id}.#{rand(1000000)}.js") end end end end
- Save the file and restart your Rails server. This changes the temp file naming pattern to reduce the chance of file locks or deletion failures.
3. Verify Temp Folder Permissions
Sometimes Windows restricts access to your temp folder, preventing ExecJS from deleting files:
- Navigate to
C:/Users/Bastian/AppData/Local/Temp - Right-click the folder, select Properties > Security
- Make sure your user account has Modify or Full Control permissions for the folder
- If not, click Edit to add your user and grant the necessary permissions, then click Apply
After trying any of these solutions, reload your Rails app's view—you should no longer see that Errno::ENOENT error.
内容的提问来源于stack exchange,提问作者xploited

