Mix project is broken when including distillery (module main is not available)

I have a project which works just fine. After I decided that it is complete, and included distillery in the project, the ran mix release, it no longer worked.

The problem it has is:

(Mix) Could not start application lzw: exited in: Main.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function Main.start/2 is undefined (module Main is not available)
            Main.start(:normal, [])
            (kernel) application_master.erl:273: :application_master.start_it_old/4

and it also displays compiler warnings for other modules not being available.
When running this project with mix run, it produces this error, when running the distillery-generated .bat file, it exits with a wall of errors (the first being that it doesn’t find the file “sys.config” at a specified path, which I can manually verify that it is there), however, when running it with “mix test”, it runs fine, just like before. What can be the problem?

The “rel” directory doesn’t contain any .beam files from my project, only mix and distillery .beam-s. The “test” directory contains every single .beam generated from my project’s source files. I suppose manually placing them from “test” to “rel” would solve the problem, but I have no idea which subdirectory should contain the compiled files.

Other info that might be useful:

  • environment is set to :prod (however, distillery seems to think it’s :dev)
  • Elixir version is 1.5.2, Distillery is 1.5.0
  • running windows 10
1 Like

You generated a project without an “application callback”, this means your application have no entry point for starting. This is the default for library applications. If you want to generate a project with an application callback and supervisor run mix new myapp --sup.

1 Like

Interesting. The application callback was defined with a start/2 in a module that use Application and a Supervisor that worked correctly, Supervisor.start_link() called from the application’s start. The same structure seems to work in this new project.

The runtime problem still persists, a call in the generated .bat file can’t find something in sys.config in the releases directory. I guess since it’s an empty project that created this error, it’s rather common.

EDIT: the application module was also defined in the configuration file for mix, it wasn’t because of that.

1 Like

What does this mean?

1 Like
def application do
    [
	  mod: {Main, []}, #it means this line
      extra_applications: [:logger]
    ]
  end
1 Like

I can not reproduce the errors you see:

mix new main --sup
cd main
# add distillery to deps
mix deps.get
mix release.init
mix release
_build/dev/rel/main/bin/main start

Running the above commands starts a working a release for me. Can you show the errors you are getting or upload a project that reproduces the error?

1 Like

I think I have hunted the bug down. The path which contained the project had a [ and a ] character in it. Using a different path, it works just fine. [[looks at Microsoft judgingly]]

Sorry for wasting everyone’s time here.

Just in case somebody runs into the same problem and wants to know the cause: the generated .bat file uses windows powershell for one action (get-content for sys.config), and powershell doesn’t seem to be working with special-character-containing paths.

2 Likes