1
votes

Using Rails 6

I have a folder like so app/client/javascript/config/editor/syntax-highlighting

2 files in there.

app/client/javascript/config/editor/syntax-highlighting/math-mode.js app/client/javascript/config/editor/syntax-highlighting/units-regex.js

When I deploy to production there error message is:

Wrong constant name Syntax-Highlighting inferred by Module from directory (Zeitwerk::NameError)

And it gives a path to that directory. app/client/javascript/config/editor/syntax-highlighting

What is the cause of this error?

2

2 Answers

4
votes

You’re placing JavaScript in a directory that gets eager loaded by Zeitwork in production. Either move the JS to an asset-specific directory (like app/assets for Sprockets or app/javascript for Webpacker) or configure Rails to ignore it:

# config/application.rb

Rails.autoloaders.main.ignore(Rails.root.join('app/path/to/dir'))
1
votes

I have this issue recently with rails/webpacker when including a hyphen in my directory name.

These worked: webpacker/images/img.jpg webpacker/images/photos/img.jpg

This caused the error webpacker/images/compound-word/img.jpg

I didn't have time to get to the bottom of it so I just changed it to webpacker/images/compoundword/img.jpg