[Bug Report] Runtime Error after running packwerk check
oskygh opened this issue · 1 comments
Description
Tried modularising an old rails app. Decided to put some parts in packages while the other parts are in the conventional rails format. After, i run packwerk check but started in run into the issues have detailed below.
Folder structure
- app
- controllers
- models
- mailers
- packages
- package_name
- app
- models
- controllers - spec
- app
- package_name
added to config/application.rb
config.autoload_paths += Dir[Rails.root / "app/packages/*/app/*"]
config.autoload_paths += Dir[Rails.root / "app/packages/*/spec/*"]
config.autoload_paths += Dir[Rails.root / "lib"]
To Reproduce
On running packwerk check you get this error We could not extract autoload paths from your Rails app. This is likely a configuration error. (RuntimeError)
Expected Behaviour
bin/packwerk check
should run successfully
Version Information
- Packwerk: [e.g. v2.2.2]
- Ruby [e.g. v2.7]
- Ruby on Rails [6.1]
- Docker
Additional Context
When i run bin/rails zeitwerk:check
, it indicates that the files in the packages needs to be eagerly loaded. When i do that, i get NameError: uninitialized constant
for some files.
Hi @oskygh !
It looks like you're having some trouble setting up autoload paths to ensure that constants are properly by zeitwerk.
Packwerk assumes your rails application is already properly set up but doesn't play a role in actually setting up, so this isn't actually a bug in packwerk, but rather a configuration issue with your Rails app (as suggested by the error message).
Stimpack actually solves this issue for you – as long as your app is structured like the one in the stimpack readme (which is pretty close to what you have now – you'll just need to move the packages up a level and set packages
as the root directory). You can check out the stimpack implementation to see more of how it adds the autoload paths. Alternatively if you want to manage autoload paths yourself, I'd recommend checking out the READMEs for zeitwerk and the Rails guide on autoloading, which I think is here.
Let me know if this helps solve your problem.