Hi all,
I have a question regarding importing packages inside a module.
I have an app that requires CSV parsing and I want to separate this logic from my main app logic. I tried to put the logic in a module but I'm not sure if/how I can import the roc-parser package from within my module. is that possible? if not, whats the proper way of separating my code when it depends on external packages?
Thanks!
Hi @Adam Bobrow,
Declaration of dependencies happens in the app file, like so:
app [main] {
cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.15.0/SlwdbJ-3GR7uBWQo6zlmYWNYOxnvo8r6YABXD-45UOw.tar.br",
parser: "https://github.com/Anton-4/roc-parser/releases/download/0.7.2/xcLMjkUXqAJoSsfKblZhVn3slAv3sdFcBxRbqBDoUJk.tar.br",
}
And in your module you should then be able to import what you need:
import parser.Core exposing [Parser, many, oneOf, map]
import parser.String exposing [parseStr, codeunit, anyCodeunit]
I'll put something together for www.roc-lang.org/examples
Hi @Anton , thank you I'll try that!
@Agus Zubiaga @Richard Feldman can you clarify if the intention is for imports to work this way into the future?
I thought I heard Agus mention that it was a work around until we have module params (which we do now), but it seems strange/unrealistic that you would have to thread something like this all the way through the application.
Specifically, should you be able to import a package from within a random module?
For context I'm just looking at https://github.com/roc-lang/examples/pull/203 and thought I'd seek clarification on this before we add an example on it.
No, this isn’t really a workaround. You should be able to import anything that’s available to the app from any of its modules.
Thank you
And hence roc "walks" back up the tree until it finds a main.roc
to see what those imports are.
Although this is still an issue or bug? we currently have. I am seeing "UNRECOGNIZED PACKAGE" errors from the LS.
Screenshot-2024-09-03-at-09.15.06.png
We’re probably going to change how platforms expose effects to the app. Right now, you can import them from its modules directly, but ideally the platform would provide them to the app’s entry point and you’d then thread them using module params.
I just realised that if I change my app.roc
to main.roc
it makes the language server happy. :smiley: I just never actually read that error message all the way through to the hint part :sweat_smile:
Yeah, at the moment the language server doesn’t haven’t a way to configure a different entry point.
The CLI, however, accepts a —main
flag to do so
Last updated: Jul 06 2025 at 12:14 UTC