jwhitley / requirejs-rails

RequireJS support for your Rails 3 or 4 application
MIT License
592 stars 202 forks source link

Assets inside of Rails Engine not precompiling #200

Closed declan closed 9 years ago

declan commented 9 years ago

I'm working on a rails engine which uses requirejs-rails to handle its javascript assets. If I mount the engine in an application, things work fine in development but crash when I try to precompile assets:

$ rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke requirejs:precompile:external (first_time)
** Invoke requirejs:test_node (first_time)
** Execute requirejs:test_node
** Execute requirejs:precompile:external
/home/declan/.rvm/rubies/ruby-2.1.2/bin/ruby /home/declan/.rvm/gems/ruby-2.1.2@coachella/bin/rake requirejs:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke requirejs:precompile:all (first_time)
** Invoke requirejs:precompile:prepare_source (first_time)
** Invoke requirejs:setup (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Execute requirejs:setup
** Invoke requirejs:clean (first_time)
** Invoke requirejs:setup 
** Execute requirejs:clean
** Execute requirejs:precompile:prepare_source
** Invoke requirejs:precompile:generate_rjs_driver (first_time)
** Invoke requirejs:setup 
** Execute requirejs:precompile:generate_rjs_driver
** Invoke requirejs:precompile:run_rjs (first_time)
** Invoke requirejs:setup 
** Invoke requirejs:test_node (first_time)
** Execute requirejs:test_node
** Execute requirejs:precompile:run_rjs
rake aborted!
Asset compilation with node failed with error:

{
  [Error: Error: ERROR: module path does not exist: /home/declan/Sites/coachella/tmp/requirejs/src/routes/home/index.js for module named: routes/home/index. 
    Path is relative to: /home/declan/Sites/coachella
    at /home/declan/.rvm/gems/ruby-2.1.2@coachella/gems/requirejs-rails-0.9.5/bin/r.js:26090:35
  ]
  originalError: [Error: ERROR: module path does not exist: /home/declan/Sites/coachella/tmp/requirejs/src/routes/home/index.js for module named: routes/home/index.
    Path is relative to: /home/declan/Sites/coachella
  ] 
}

/home/declan/.rvm/gems/ruby-2.1.2@coachella/gems/requirejs-rails-0.9.5/lib/tasks/requirejs-rails_tasks.rake:139:in `block (3 levels) in <top (required)>'

This seems like a path issue? If I manually copy all the javascript files from the engine into app/assets/javascripts then things work fine.

I've tried solving the problem by prefixing the paths in requirejs.yml with the engine name, but if a file inside the engine requires another file inside the engine, the compilation crashes with the same error as above.

declan commented 9 years ago

Just to elaborate on requirejs.yml, it initially looked like this and was working fine in development:

modules:
  - name: 'routes/home/index'
  - name: 'routes/about/index'

If I change it to

modules:
  - name: 'ohana/routes/home/index'

Then that works fine, as long as routes/home/index.js does not require any other modules. If it does, then I get the same crash as above.

carsomyr commented 9 years ago

@declan Sorry for the belated reply. I read over your bug report, and it seems like you're still requiring routes/home/index as a dependency from some module when the module in question has already moved to the new location app/assets/javascripts/ohana/routes/home/index.js. Is that the case? If it is, you'll see the error above and will have to update dependency declarations accordingly. If it isn't, I'll reopen.