{"record":{"id":"20fa687a2d54ad3a","repo":"gleam-lang/gleam","slug":"javascript-generator-could-not-identify-imported-module-name","errorCode":null,"errorMessage":"JavaScript generator could not identify imported module name.","messagePattern":"JavaScript generator could not identify imported module name\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/javascript.rs","lineNumber":166,"sourceCode":"                None\n            },\n            stdlib_package,\n        }\n    }\n\n    fn type_reference(&self, arena: &'doc DocumentArena<'a, 'doc>) -> Document<'a, 'doc> {\n        if self.typescript == TypeScriptDeclarations::None {\n            return EMPTY_DOCUMENT;\n        }\n\n        // Get the name of the module relative the directory (similar to basename)\n        let module = self\n            .module\n            .name\n            .as_str()\n            .split('/')\n            .next_back()\n            .expect(\"JavaScript generator could not identify imported module name.\");\n\n        docvec![\n            arena,\n            REFERENCE_TYPES_DOCUMENT,\n            module,\n            DOT_D_DOT_MTS_CLOSE_QUOTE_CLOSE_TAG_DOCUMENT,\n            LINE_DOCUMENT\n        ]\n    }\n\n    fn sourcemap_reference(&self, arena: &'doc DocumentArena<'a, 'doc>) -> Document<'a, 'doc> {\n        match self.source_map_builder {\n            None => \"\".to_doc(arena),\n            Some(_) => {\n                // Get the name of the module relative the directory (similar to basename)\n                let module = self\n                    .module\n                    .name","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/javascript.rs#L148-L184","documentation":"When generating JavaScript type references, the generator derives a module name by taking the last '/'-separated segment of the imported module's name. The expect asserts module names are never empty or slash-terminated; a module whose name yields None from next_back() breaches that assumption.","triggerScenarios":"Compiling an import whose module `name` is empty or ends such that split('/').next_back() returns None/empty (e.g. name == \"\" or \"a/b/\"), then hitting the type_reference path that emits a .d.mts reference.","commonSituations":"Compiler development or hand-crafted module graphs (tests, codegen tools) with malformed module names; typically not reachable from valid Gleam source where module names are validated identifiers.","solutions":["Ensure every module has a non-empty, validated name before compilation.","Add upstream validation rejecting module names that are empty or end with '/'.","Replace expect with a proper compiler error (InternalError) reporting the offending module name."],"exampleFix":"// before\n.next_back()\n.expect(\"JavaScript generator could not identify imported module name.\")\n// after\n.next_back()\n.filter(|s| !s.is_empty())\n.unwrap_or_else(|| panic!(\"invalid module name: {:?}\", self.module.name))","handlingStrategy":"validation","validationCode":"fn module_ref_ok(name: &str) -> bool { name.rsplit('/').next().map_or(false, |s| !s.is_empty()) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate module names at parse/definition time (non-empty, no trailing slash).","Never construct Module records with empty names, even in tests/tools.","Turn this expect into a proper compiler diagnostic with the module name."],"tags":["rust","javascript","codegen","panic"],"backgroundTag":"internal-invariant-violation","analyzedSha":"15b07c783065c92bb016b1b74ed0995a5259850f","analyzedAt":"2026-09-14T11:14:59.388Z","contentChangedAt":"2026-09-14T11:14:59.388Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}