gleam-lang/gleam

echo shows dicts using JS syntax in wasm compiler (tour, playground)

Open

#5592 opened on Apr 8, 2026

View on GitHub
 (0 comments) (0 reactions) (0 assignees)Rust (21,417 stars) (960 forks)batch import
discussionhelp wanted

Description

import gleam/dict

pub fn main() {
  echo dict.from_list([])
}

Expected output

src/main.gleam:4
dict.from_list([])

Actual output

src/main.gleam:4
//js(Dict { "size": 0, "root": //js({ "datamap": 0, "nodemap": 0, "data": #() }) })

For echo the compiler checks if the stdlib is present and adds an import for the echo code to use if it is. In the wasm compiler the package config does not have any dependencies specified, so no import is added, and the echo code falls back to the JS syntax at runtime.

Users of the wasm compiler may not provide the stdlib, so we cannot add register the dependency as present without generating invalid code importing a module that doesn't exist. Even if the gleam/dict module is present for that user they may have it at a different location, as they're not using the Gleam build tool.

It's unclear to me what the right thing to do is here. We could possibly have users of the wasm compile configure the location of the module, but that seems like a very ugly solution to me.

Playground reproduction: https://playground.gleam.run/#N4IgbgpgTgzglgewHYgFwEYA0IDGyAuES+aIcAtgA4JT4AEA5gDYQCG5A9ACZw74A6SQZQCuAIzoAzJHXKs4SABQBKOsEF06EHAAsEdHnwB0kqAnIB9JnBj5FAbQC6ywQF9BIV0A

Contributor guide