Require module under lib/ in the mix task, in :prod env

I build a mix task under lib/mix/tasks\example , which require a module under lib\example, like this

This task runs under :dev env smoothly, but when in :prod env, I always get a function Example.Elasticsearch.clear_all/0 is undefined (module Example.Elasticsearch is not available).

Did I miss anything? Thanks!

I think this has something to do with Example.Elasticsearch is not compiled when you call the task in production mode.

could you delete the _build folder to remove the current build, then run mix compile in both dev and production enviroment and check that the Example.Elasticsearch is compiled. I think by doing this will allow us to replicate Example.Elasticsearch not compile from prod mode into dev mode so we can see what went wrong.

I hope this may help

1 Like