Importing a Package from a Module
You probably know how to add a package in an app file, for example with the unicode package:
Validated with Roc nightly-2026-11-12-ce942d6.
app [main!] { cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.28.0/2yhxoR7cZPSYbyUzPWULFw8AA6QEcdsgFNRmzu7pZbst.tar.zst", roc: "nightly-2026-11-12-ce942d6", unicode: "https://github.com/roc-lang/unicode/releases/download/4.3.2/3gvgiWm6BShjHKbNV2zRH6fhC5ZvScZgWF7AnVDWHSdd.tar.zst", }
But how can you add a package inside a module file? All dependencies go in the app file!
So we have the app file just like before:
### start snippet header app [main!] { cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.28.0/2yhxoR7cZPSYbyUzPWULFw8AA6QEcdsgFNRmzu7pZbst.tar.zst", roc: "nightly-2026-11-12-ce942d6", unicode: "https://github.com/roc-lang/unicode/releases/download/4.3.2/3gvgiWm6BShjHKbNV2zRH6fhC5ZvScZgWF7AnVDWHSdd.tar.zst", } ### end snippet header import cli.Stdout import Module main! = |_args| { Module.split_graphemes("hello") |> Str.inspect |> Stdout.line! }
And the unicode import goes in the module file:
import unicode.Grapheme Module :: {}.{ split_graphemes = |string| Grapheme.split(string) }
Output
Run this from the directory that has main.roc in it:
$ roc main.roc Ok(["h", "e", "l", "l", "o"])