gleam-lang/gleam
View on GitHubElixir external functions don't work when no Elixir modules are present
Open
#1,986 opened on Feb 3, 2023
discussionhelp wanted
Description
When generating a new Gleam project:
gleam new exffi
And adding an FFI function to Elixir:
import gleam/io
pub fn main() {
io.println("Hello from " <> cwd())
}
external fn cwd() -> String =
"Elixir.File" "cwd!"
Calling the function results in:
exffi:main().
% ** exception error: undefined function 'Elixir.File':'cwd!'/0
% in function exffi:main/0 (build/dev/erlang/exffi/_gleam_artefacts/exffi.erl, line 8)
Elixir files are not being generated in the build directory until there's an elixir dependency:

Adding a .ex file to the project generates the files and solves this issue.