rails/sprockets-rails

rake assets:precompile generates a "Sprockets::NotImplementedError: Custom asset_path helper is not implemented" error

guillaumebesse opened this issue · 0 comments

I spent the last two days trying to fix this problem appearing on a rake assets:precompile task without success.

I am migrating from

  • rails 6.0.1 -> 7.0.1
  • webpack -> esbuild

I use tailswindcss / stimulus with ruby 3.0.3

Everything works well locally using bin/dev

It looks like sprocket is trying to insert some kind of sourceMappingURL in application.js.
Update: I unregister SourcemappingUrlProcessor postprocessor and now the error is in AssetUrlProcessor

Here is the full trace. Any help or idea is welcome.

~/Pro/xxx │ feature/migrate_to_rails_7 > rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke javascript:build (first_time)
** Execute javascript:build
yarn install v1.22.10
[1/4] 🔍  Resolving packages...
success Already up-to-date.
✨  Done in 0.16s.
yarn run v1.22.10
$ node esbuild.config.js
✨  Done in 0.32s.
** Invoke css:build (first_time)
** Execute css:build
yarn install v1.22.10
[1/4] 🔍  Resolving packages...
success Already up-to-date.
✨  Done in 0.15s.
yarn run v1.22.10
$ tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css

Done in 1096ms.
✨  Done in 1.67s.
** Invoke tailwindcss:build (first_time)
** Execute tailwindcss:build
+ /Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/tailwindcss-rails-2.0.5-x86_64-darwin/exe/x86_64-darwin/tailwindcss -i /Users/besse/Projects/chefsimon/app/assets/stylesheets/application.tailwind.css -o /Users/besse/Projects/chefsimon/app/assets/builds/tailwind.css -c /Users/besse/Projects/chefsimon/tailwind.config.js

Done in 1015ms.
** Execute assets:precompile
TRACE: source_file=stimulus.min $1=stimulus.min.js.map match=//# sourceMappingURL=stimulus.min.js.map
rake aborted!
Sprockets::NotImplementedError: Custom asset_path helper is not implemented

Extend your environment context with a custom method.

    environment.context_class.class_eval do
      def asset_path(path, options = {})
      end
    end
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/context.rb:226:in `asset_path'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/sourcemapping_url_processor.rb:44:in `sourcemap_asset_path'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/sourcemapping_url_processor.rb:37:in `resolved_sourcemap_comment'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/sourcemapping_url_processor.rb:17:in `block in call'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/sourcemapping_url_processor.rb:12:in `gsub'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/sourcemapping_url_processor.rb:12:in `call'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:84:in `call_processor'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `call_processors'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:182:in `load_from_unloaded'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:59:in `block in load'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:43:in `load'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/cached_environment.rb:44:in `load'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/bundle.rb:27:in `call'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:84:in `call_processor'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:65:in `call_processors'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:182:in `load_from_unloaded'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:59:in `block in load'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/loader.rb:43:in `load'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/cached_environment.rb:44:in `load'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/base.rb:81:in `find_asset'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/base.rb:88:in `find_all_linked_assets'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/sprockets-4.0.2/lib/sprockets/manifest.rb:125:in `block (2 levels) in find'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:24:in `block in execute'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `block in synchronize'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `synchronize'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `synchronize'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:19:in `execute'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/promise.rb:564:in `block in realize'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:363:in `run_task'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:352:in `block (3 levels) in create_worker'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:335:in `loop'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:335:in `block (2 levels) in create_worker'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `catch'
/Users/besse/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `block in create_worker'
Tasks: TOP => assets:precompile