{"record":{"id":"99883f3fd811d6f0","repo":"oxc-project/oxc","slug":"arbitrary-module-namespace-identifier-names-are-no","errorCode":null,"errorMessage":"Arbitrary module namespace identifier names are not available in the configured target environment.","messagePattern":"Arbitrary module namespace identifier names are not available in the configured target environment\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_transformer/src/es2020/mod.rs","lineNumber":91,"sourceCode":"    fn enter_big_int_literal(&mut self, node: &mut BigIntLiteral<'a>, ctx: &mut TraverseCtx<'a>) {\n        if self.options.big_int {\n            let warning = OxcDiagnostic::warn(\n                \"Big integer literals are not available in the configured target environment.\",\n            )\n            .with_label(node.span);\n            ctx.state.error(warning);\n        }\n    }\n\n    fn enter_import_specifier(\n        &mut self,\n        node: &mut ImportSpecifier<'a>,\n        ctx: &mut TraverseCtx<'a>,\n    ) {\n        if self.options.arbitrary_module_namespace_names\n            && let ModuleExportName::StringLiteral(literal) = &node.imported\n        {\n            let warning = OxcDiagnostic::warn(\n                \"Arbitrary module namespace identifier names are not available in the configured target environment.\",\n            )\n            .with_label(literal.span);\n            ctx.state.error(warning);\n        }\n    }\n\n    fn enter_export_specifier(\n        &mut self,\n        node: &mut ExportSpecifier<'a>,\n        ctx: &mut TraverseCtx<'a>,\n    ) {\n        if self.options.arbitrary_module_namespace_names {\n            if let ModuleExportName::StringLiteral(literal) = &node.exported {\n                let warning = OxcDiagnostic::warn(\n                    \"Arbitrary module namespace identifier names are not available in the configured target environment.\",\n                )\n                .with_label(literal.span);","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_transformer/src/es2020/mod.rs#L73-L109","documentation":"Warning raised by the oxc transformer's ES2020 pass (crates/oxc_transformer/src/es2020/mod.rs, `enter_import_specifier`). When `arbitrary_module_namespace_names` is enabled (compile target predates the ES2022 feature) and an ImportSpecifier's `imported` name is a StringLiteral, the pass records this diagnostic. `import { \"odd name\" as x } from 'm'` is the ES2022 'arbitrary module namespace names' feature; oxc has no downlevel transform for it, so the string-named import is reported and passes through unchanged.","triggerScenarios":"Transforming `import { \"string name\" as local } from './mod'` (note the quoted string in the import position) with a target below ES2022 / options.arbitrary_module_namespace_names = true. One diagnostic per offending specifier, labeled with the string literal's span.","commonSituations":"Consuming generated or interop-oriented packages that export non-identifier names (e.g. `import { \"jest-mock\" as mock }`); transpiling with legacy browserslist targets; bundler output that preserved string import names from a source file.","solutions":["Raise the target to ES2022+ so arbitrary module namespace names are supported natively.","Rewrite the import to a plain identifier if the module also exports an identifier binding, or re-export the string-named export under an identifier name in a small helper module.","Use a namespace import instead: `import * as m from './mod'` and access `m['odd name']`.","Remove the import if it is unused."],"exampleFix":"// before\nimport { \"odd-name\" as oddName } from './mod';\n\n// after\nimport * as m from './mod';\nconst oddName = m['odd-name'];","handlingStrategy":"validation","validationCode":"// Detect string-named imports (ES2022 arbitrary module namespace names)\nif (/import\\s*\\{\\s*[\"'][^\"']+[\"']\\s+as\\s+/.test(source)) {\n  throw new Error('String-named import requires an ES2022+ target or must be rewritten');\n}","typeGuard":null,"tryCatchPattern":"const result = transform('foo.ts', source, options);\nconst nsErrors = result.errors.filter(e => e.message.includes('Arbitrary module namespace'));\nif (nsErrors.length) { /* raise target or rewrite the imports, then fail the build */ }","preventionTips":["Prefer identifier imports; keep string names only at interop boundaries with a modern target.","Set target once from browserslist and verify it is ES2022+ before adopting string-named imports.","Fail builds on any transformer diagnostic rather than shipping untransformed syntax."],"tags":["oxc","transformer","es2022","modules","import","compile-target"],"backgroundTag":"syntax-not-supported-by-compile-target","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}