# E4069

Unexpected main function in the non-main package.

In MoonBit, packages are divided into two types: main packages and non-main
packages. Non-main packages are often used as libraries to provide functionality
to other packages. Main packages, on the other hand, are the entry points of the
program. Therefore, non-main packages should not contain a `main` function.

Sometimes, people use the main function for testing. In such cases, we recommend
using the `test` block to write tests, instead of using the `main` function. See
the [test](../introduction.md#test) section of the MoonBit documentation for
more information.

## Erroneous example

Suppose in package `lib`:

`lib/moon.pkg.json`:

```json
{} // "is-main" is by default false
```

`lib/lib.mbt`:

```{literalinclude} /sources/error_codes/E4069_error/top.mbt
:language: moonbit
```

## Suggestion

You can remove the `main` function from the non-main package:

```{literalinclude} /sources/error_codes/E4069_fixed/top.mbt
:language: moonbit
```

Alternatively, you can set the package to be a main package by setting
`"is-main"` to `true` in the package configuration file.

`lib/moon.pkg.json`:

```json
{
  "is-main": true
}
```

You can also move the `main` function to a different package, say `main`:

`main/moon.pkg.json`:

```json
{
  "is-main": true
}
```

`main/main.mbt`:

```{literalinclude} /sources/error_codes/E4069_fixed/top_1.mbt
:language: moonbit
```
