Stream: beginners

Topic: Local imports not working


view this post on Zulip Hannes (Feb 21 2023 at 06:28):

Hi, I'm using the latest roc nightly build (commit c6089eb on Mo 20 Feb 2023) and trying to build an app that imports a local library.

My folders are laid out like this:

.
├── bin
│   └── main.roc
└── MyLib
    └── main.roc

With this in the MyLib/main.roc:

package "MyLib"
    exposes [greet]

greet = \person -> "Hello, \(person)!"

And this in the bin/main.roc:

app "Hello"
    packages {
        pf: "https://github.com/roc-lang/basic-cli/releases/download/0.2.0/8tCohJeXMBUnjo_zdMq0jSaqdYoCWJkWazBd4wa8cQU.tar.br",
      MyLib:"../MyLib/main.roc"
    }
    imports [pf.Stdout, MyLib.{greet}]
    provides [main] to pf

main =
   pf.Stdout (greet "world")

I'm running this command to try and build the app:

roc dev bin/main.roc

but I get this error:

thread 'main' panicked at 'not yet implemented: unhandled parse error ListEnd(@161)', crates/reporting/src/error/parse.rs:3794:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

which seems to suggest some feature I'm using is not implemented, but I'm not sure which one.

Thanks in advance!

view this post on Zulip Anton (Feb 21 2023 at 08:26):

I think the MyLib header needs to be:

package "MyLib"
    exposes [greet]
    packages {}

I'll check locally to confirm

view this post on Zulip Hannes (Feb 21 2023 at 08:54):

Thanks for your help Anton, I tried adding packages {} to the MyLib/main.roc file, but I'm still getting the same error, is it the same for you?

view this post on Zulip Anton (Feb 21 2023 at 09:26):

Yes, it's the same for me. I have to go out for about an hour, I'll investigate further when I'm back.

view this post on Zulip Anton (Feb 21 2023 at 11:01):

I got it to work with the following modifications:

package "MyLib"
    exposes [ Greeter ]
    packages {}

And I made a new file in the MyLib folder called Greeter.roc:

interface Greeter
    exposes [ greet ]
    imports []

greet = \person -> "Hello, \(person)!"

I'm not sure if package modules are supposed to support functions in the file but I'll make an issue to improve the error message.

view this post on Zulip Anton (Feb 21 2023 at 11:21):

#5058

view this post on Zulip Hannes (Feb 21 2023 at 14:17):

Thanks Anton, can you share what your bin/main.roc looks like please? I tried making the changes you suggested, but I'm still getting the same error for some reason

view this post on Zulip Anton (Feb 21 2023 at 14:20):

Oh right, I forgot about the import change in bin/main.roc, I've deleted the file now but I think this should work:

imports [pf.Stdout, MyLib.Greeter.{greet}]

view this post on Zulip Hannes (Feb 21 2023 at 14:57):

Thanks, I'm having trouble building the app when I include MyLib: "../MyLib/main.roc" in the list of packages. If I rearrange the files to be like this:

.
├── main.roc
└── MyLib
    ├── Greeter.roc
    └── main.roc

and I remove the MyLib entry from the list of packages then I can import MyLib into the app.

I know the Roc compiler has rules about finding modules by looking for a file called MyLib.roc and MyLib/main.roc, but do you know if it's possible to use the packages list to tell the Roc compiler to look in a different folder for the library?

view this post on Zulip Anton (Feb 21 2023 at 15:27):

Yes, the approach you were using with the ../ was working for me. I'll set up and test a folder locally and send you a compressed archive.

view this post on Zulip Hannes (Feb 21 2023 at 15:31):

Thank you! Which version of the Roc compiler are you using? I hope it's not a version mismatch error! :sweat_smile:

view this post on Zulip Anton (Feb 21 2023 at 15:32):

I'm testing with the latest main, built from source. If you still have problems with my archive, I can check with your version but I don't think that's likely unless your version is say months old.

view this post on Zulip Hannes (Feb 21 2023 at 15:36):

Okay, I'm using the nightly from 20th February, so should be all good :)

view this post on Zulip Anton (Feb 21 2023 at 15:44):

Now I can't get back to my working version :p I'll figure it out though...

view this post on Zulip Hannes (Feb 21 2023 at 16:17):

Haha, I'll pick this up again tomorrow, thanks for your help :+1:

view this post on Zulip Anton (Feb 21 2023 at 17:38):

Alright here it is: parse_error.tar.gz
So all changes required compared to the original:

view this post on Zulip Brendan Hansknecht (Feb 21 2023 at 17:43):

Oh, this is the issue where only for packages, exposes means something different. For packages, you can't expose functions or types directly, you have to expose interfaces in another file. Those can then expose functions and types.

view this post on Zulip Brendan Hansknecht (Feb 21 2023 at 17:43):

I think we really need to fix the naming here to make this clearer. Or change the semantics or something

view this post on Zulip Nick Hallstrom (Feb 21 2023 at 18:28):

What is a package? I’ve only seen Interface before

view this post on Zulip Anton (Feb 21 2023 at 18:32):

I think package is for when you want to make a pure roc "library".

view this post on Zulip Anton (Feb 21 2023 at 18:33):

Here is an example

view this post on Zulip Anton (Feb 21 2023 at 18:50):

@Hannes your example revealed 4 different cases where error messages could be improved so thank you as well :)

view this post on Zulip Hannes (Feb 22 2023 at 01:15):

Thanks Anton for all your help, I was really confused by why it would sometimes work and other times would error. I 'll look at the Roc compiler code and might try contributing fixes for some of these problems :)

view this post on Zulip Luke Boswell (Feb 22 2023 at 07:08):

There is only a very brief description of the modules in the tutorial at the moment. Linking here for anyone who finds this thread.

Each .roc file is a separate module and contains Roc code for different purposes. Here are all of the different types of modules that Roc suppports;


Last updated: Jul 06 2025 at 12:14 UTC