Phoenix Project not Compiling - (Mix) Could not find a Mix.Project

Hello everyone, I created new project with mix phx.new projectName command but when its ask Fetch and install dependencies? [Yn] and I hit enter then it will get stuck, I have waited for hours, but it wont work, then when I break out of it and try to run mix deps.get then I will get this error (Mix) Could not find a Mix.Project, please ensure you are running Mix in a directory with a mix.exs file then when I run this cd projectName and then run mix deps.get then it will work, but if I tried to compile the project it will get stuck here
C:\Users\seyi\Desktop\EL\new>mix compile ==> file_system Compiling 7 files (.ex) Generated file_system app ==> decimal Compiling 4 files (.ex) Generated decimal app ==> mime Compiling 1 file (.ex) Generated mime app ==> nimble_options Compiling 3 files (.ex) Generated nimble_options app

Please am new to elixir I will really appriciate your help, Thanks

after the ph.new projectName, did you cd projectName into the folder? within your app folder is the place to run mix deps.get or mix compile

I also see you’re on windows, so this might differ a bit

Is that the full trace when you ran mix compile? There are no errors as far as I see. What happens if you run iex -S mix phx.server?

$ iex -S mix phx.server
Erlang/OTP 26 [erts-14.0.2] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit:ns]

==> file_system
Compiling 7 files (.ex)
Generated file_system app
==> decimal
Compiling 4 files (.ex)
Generated decimal app
==> mime
Compiling 1 file (.ex)
Generated mime app
==> nimble_options
Compiling 3 files (.ex)
Generated nimble_options app


its get stuck right here without any error message

Yes I cd projectName into the folder and mix deps.get works but, Compiling didnt working Even if I try running the server

What version of Elixir and Erlang are you running?

Elixir 1.14.2 (compiled with Erlang/OTP 25)

Based on the log you posted above you’re running OTP 26:

$ iex -S mix phx.server
Erlang/OTP 26 [erts-14.0.2] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit:ns]

And Elixir 1.14 only supports OTP 26 if it 1.14.5 or later (and you’re using 1.14.2): Compatibility and Deprecations β€” Elixir v1.14.5

So I’d either upgrade elixir to 1.15 or downgrade Erlang/OTP to 25. I’d guess that upgrading Elixir is probably easier, although I haven’t tried using Elixir on Windows.

3 Likes

I just want to add that you should use snake_case (mix phx.new project_name) instead of camelCase (mix phx.new projectName) when generating your projects.

I’m not just saying that to be pedantic (although it does match the Elixir style guide…), but the project auto-generates a lot of stuff (e.g. when creating modules) and I could see some parser somewhere getting confused by the cases getting mixed up.

Out of curiosity, I tried generating the same project, and the module names work as expected (e.g. ProjectNameWeb) but some of the filenames are kinda wonky. Here’s the tree output of the lib/ directory:

β”œβ”€β”€ projectName
β”‚   β”œβ”€β”€ application.ex
β”‚   β”œβ”€β”€ mailer.ex
β”‚   └── repo.ex
β”œβ”€β”€ projectName.ex
β”œβ”€β”€ projectName_web
β”‚   β”œβ”€β”€ components
β”‚   β”‚   β”œβ”€β”€ core_components.ex
β”‚   β”‚   β”œβ”€β”€ layouts
β”‚   β”‚   β”‚   β”œβ”€β”€ app.html.heex
β”‚   β”‚   β”‚   └── root.html.heex
β”‚   β”‚   └── layouts.ex
β”‚   β”œβ”€β”€ controllers
β”‚   β”‚   β”œβ”€β”€ error_html.ex
β”‚   β”‚   β”œβ”€β”€ error_json.ex
β”‚   β”‚   β”œβ”€β”€ page_controller.ex
β”‚   β”‚   β”œβ”€β”€ page_html
β”‚   β”‚   β”‚   └── home.html.heex
β”‚   β”‚   └── page_html.ex
β”‚   β”œβ”€β”€ endpoint.ex
β”‚   β”œβ”€β”€ gettext.ex
β”‚   β”œβ”€β”€ router.ex
β”‚   └── telemetry.ex
└── projectName_web.ex

Notice how the projectName_web module filename looks, ahem strange. This can be avoided by using snake_case when generating the projects (one less PITA to deal with, you know?).

2 Likes