The task "docs" could not be found. Did you mean "do"?
Asked Answered
R

6

5

How to generate documentation for mix project? How it can do it?

The procedure for working with the Elixir mix-project:

  • I generate a project by mix new greeter command.
  • I add a block of comments in the greeter.ex file.
  • I add dependencies to the mix.exs file.
  • I try to generate documentation by mix docs command.

mix help can not provide docs task in a list of possible options:

mix                   # Runs the default task (current: "mix run")
mix app.start         # Starts all registered apps
mix app.tree          # Prints the application tree
mix archive           # Lists installed archives
mix archive.build     # Archives this project into a .ez file
mix archive.install   # Installs an archive locally
mix archive.uninstall # Uninstalls archives
mix clean             # Deletes generated application files
mix cmd               # Executes the given command
mix compile           # Compiles source files
mix deps              # Lists dependencies and their status
mix deps.clean        # Deletes the given dependencies' files
mix deps.compile      # Compiles dependencies
mix deps.get          # Gets all out of date dependencies
mix deps.tree         # Prints the dependency tree
mix deps.unlock       # Unlocks the given dependencies
mix deps.update       # Updates the given dependencies
mix dialyzer          # Runs dialyzer with default or project-defined flags.
mix dialyzer.build    # Build the required plt(s) and exit.
mix dialyzer.clean    # Delete plt(s) and exit.
mix dialyzer.explain  # Display information about dialyzer warnings.
mix do                # Executes the tasks separated by comma
mix escript           # Lists installed escripts

When I run mix docs command I get a mix-message:

**(Mix) The task "docs" could not be found. Did you mean "do"?

Resolving Hex dependencies...
Dependency resolution completed:
Unchanged:
  earmark 1.3.2
  ex_doc 0.20.2
  makeup 0.8.0
  makeup_elixir 0.13.0
  nimble_parsec 0.5.0
All dependencies are up to date

What is my mistake?

Rowdy answered 23/5, 2019 at 7:44 Comment(0)
R
3

I remove _build directory, remove all content of deps directory, remove mix.lock.

Then in a command line of mix-project I do commands:

  1. mix deps.clean --all
  2. mix deps.update --all
  3. mix deps.get --all

After that, I run mix docs and documentation was generated.

Command mix help docs print ExDoc documentation too.

Rowdy answered 23/5, 2019 at 9:11 Comment(0)
E
9

The mix docs task is available with ExDoc. Make sure that you have the dependency installed. Make sure to check out the docs and install it properly. Then you'll be able to use the mix docs command.

This is how to install it:

  • Add it to your dependencies in mix.exs:

for Elixir >= 1.7:

def deps do
  [
    {:ex_doc, "~> 0.19", only: :dev, runtime: false},
  ]
end

Elixir < 1.7:


def deps do
  [
    {:ex_doc, "~> 0.18.0", only: :dev, runtime: false},
  ]
end
  • Run mix deps.get
  • Run mix docs

There are things you can configure in the project function of your mix file. Such as the name, source_url and homepage_url. Make sure to check out ExDoc's documentation for more details.

Concerning the "task could not be found" error, mix help lists tasks for the current environment. The default mix environment is :dev, and above ex_doc was added to the :dev environment. However, some projects use a :docs environment, instead of :dev.

Also, mix tasks can be provided by compilation, so you may need compile first (also respecting the environment, as above).

So, if the mix docs task is not listed by mix help or "could not be found", be sure to run mix compile and mix help in the environment of the ex_doc dependency. For example, run MIX_ENV=docs mix compile, then MIX_ENV=docs mix help or MIX_ENV=docs mix docs.

Eddy answered 23/5, 2019 at 7:57 Comment(2)
It should work like this, but for some reason it does not work. Elixir version is 1.8.2. My mix.exs file contains ( ``` def deps do [ {:ex_doc, "~> 0.19", only: :dev, runtime: false}, ]) ``` I try to do a description of elixirschool.com/en/lessons/basics/documentation material. I have done all you describe. Unfortunately, all this does not lead to the generation of documentation.Rowdy
I read ExDoc documentation. I would like to see all options available when generating docs, run mix help docs. I can't - ** (Mix) The task "docs" could not be found. Did you mean "do"?Rowdy
R
3

I remove _build directory, remove all content of deps directory, remove mix.lock.

Then in a command line of mix-project I do commands:

  1. mix deps.clean --all
  2. mix deps.update --all
  3. mix deps.get --all

After that, I run mix docs and documentation was generated.

Command mix help docs print ExDoc documentation too.

Rowdy answered 23/5, 2019 at 9:11 Comment(0)
P
1

If you installed ex_doc with

{:ex_doc, "~> 0.19", only: :dev, runtime: false},

It will not work if you are running in :prod mode. You need to remove only :dev from the line above.

Ploughman answered 2/5, 2020 at 17:42 Comment(0)
S
1

This kind of error comes when we have a dependency which is available only for some environment like only :test or :dev so to fix this issue please make sure that particular dependency is available in required environment

{:ex_doc, ">= 0.0.0", runtime: false}

Update it like this and it should solve the issue.

Septic answered 15/7, 2020 at 10:54 Comment(1)
You can also uses MIX_ENV=the-env mix ....Dissimulate
A
0

For me the problem was I had set preferred_cli_env: [docs: :docs] and yet {:ex_doc, "~> 0.31", only: :dev, runtime: false},

So mix docs was always using MIX_ENV=docs where ex_doc was not available.

Changing the ex_doc dependency to only: :docs fixed the problem.

Alienate answered 11/2 at 14:15 Comment(0)
B
-1

For my project mix do docs worked.

Blarney answered 8/10, 2019 at 11:45 Comment(1)
That is no different from mix docs.Yamashita

© 2022 - 2024 — McMap. All rights reserved.