rake assets:precompile undefined method directory?

2019-02-21 14:44发布

问题:

While trying to do an assets:precompile for a production website I've encountered this error for the first time.

 rake assets:precompile undefined method directory? for nil:NilClass

I have successfully updated the website and done a assets:precompile many times before.

The full example:

# RAILS_ENV=production rake assets:precompile --trace                        
/usr/local/rvm/gems/ruby-1.9.2-p290@pm/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53: warning: already initialized constant WFKV_
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/usr/local/rvm/gems/ruby-1.9.2-p290@pm/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53: warning: already initialized constant WFKV_
rake aborted!
undefined method `directory?' for nil:NilClass

Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

I'm looking forward to someone's insight in this one, I've been racking my brain and Googling answers for hours.

回答1:

This is what happens when the file system can't find one of the assets it thinks its supposed to precompile. This happened to me when my VM could not find one of the files in my shared folder (Weird VMware issue where it appeared in the directory listing but the file did not actually exist)



回答2:

I had created a symbolic link to a non-existent file by mistake in the assets/javascript directory. Removing the link fixed the problem. Note that I do have other links in the assets directory so links in general are not a problem.



回答3:

In my case, I had this issue when deploying an application in Heroku. And one of my files was symlinked to somewhere outside the GIT repository, so the file was not present int 'master'.

I then had to remove the symbolic link (rm .../file) then copy the original file (cp file1 .../file) and finally add it to the repository (git -a -m "Added a forgotten file")