Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uglifier::Error during assets:precompile #591

Open
rzane opened this issue Feb 21, 2024 · 4 comments
Open

Uglifier::Error during assets:precompile #591

rzane opened this issue Feb 21, 2024 · 4 comments

Comments

@rzane
Copy link

rzane commented Feb 21, 2024

It looks like this issue has come up before, but with a different version of Turbo. I'm using turbo-rails v2.0.3.

$ bundle exec rails assets:precompile                     
rails aborted!
Uglifier::Error: Unexpected token: keyword (const). To use ES6 syntax, harmony mode must be enabled with Uglifier.new(:harmony => true). (Uglifier::Error)
--
 22     submitter.type == "submit" || raise(TypeError, "The specified element is not a submit button");
 23     submitter.form == form || raise(DOMException, "The specified element is not owned by this form element", "NotFoundError");
 24   }
 25   function raise(errorConstructor, message, name) {
 26     throw new errorConstructor("Failed to execute 'requestSubmit' on 'HTMLFormElement': " + message + ".", name);
 27   }
 28 })(HTMLFormElement.prototype);
 29 
 => const submittersByForm = new WeakMap;
 31 
 32 function findSubmitterFromClickTarget(target) {
 33   const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;
 34   const candidate = element ? element.closest("input, button") : null;
 35   return candidate?.type == "submit" ? candidate : null;
 36 }
 37 
 38 function clickCaptured(event) {
==

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

I followed the error message and added the following configuration.

config.assets.js_compressor = Uglifier.new(harmony: true)

But, unfortunately, I get the same error.

@rzane
Copy link
Author

rzane commented Feb 21, 2024

In my case, I don't actually want to precompile Turbo since I'm sourcing it from NPM. For me, this is the best solution: https://github.com/hotwired/turbo-rails/blob/v2.0.3/lib/turbo/engine.rb#L22-L27

@jeffcoh23
Copy link

@rzane Did you ever figure out the issue? I'm pretty stuck on this and not sure what to do. I need my app to work on older iOS versions.

@timhaak
Copy link

timhaak commented Jul 1, 2024

I think from the link the fix is to add

if config.assets.compile
config.after_initialize do
config.assets.precompile -= Turbo::Engine::PRECOMPILE_ASSETS
end
end

Which seems to have fixed the problem on my side

@kabasawakyohei
Copy link

In my case, my product used the uglifier gem to compress JavaScript, so I resolved the issue by switching to terser for compression. Note that uglifier mentions, “UglifyJS only works with ES5. If you need to compress ES6, ruby-terser is a better option.”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants