{"record":{"id":"48814658ac14cf05","repo":"karatelabs/karate","slug":"invalid-sitename-import-meta","errorCode":null,"errorMessage":"invalid ${siteName}: import.meta","messagePattern":"invalid (.+?): import\\.meta","errorType":"exception","errorClass":"ParserException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/parser/JsParser.java","lineNumber":1734,"sourceCode":"                        && n.getFirst().type == NodeType.FN_ARROW_EXPR) {\n                    throw new ParserException(\"invalid \" + siteName + \": arrow function\");\n                }\n                // `this` lexes as IDENT (see JsLexer.keywordOrIdent) but per spec\n                // the ThisExpression has AssignmentTargetType=invalid.\n                if (n.size() >= 1 && n.getFirst().isToken()\n                        && n.getFirst().token.type == IDENT\n                        && \"this\".equals(n.getFirst().getText())) {\n                    throw new ParserException(\"invalid \" + siteName + \": this\");\n                }\n            }\n            case REF_DOT_EXPR, REF_BRACKET_EXPR -> {\n                // Plain member access; a `?.` would have been caught earlier by\n                // the optional-chain branch above with a more specific message.\n                // `import.meta` is a meta-property whose AssignmentTargetType is\n                // invalid; `import` is not a reserved word in our lexer so it\n                // parses as a normal REF_DOT_EXPR — flag the literal shape here.\n                if (n.type == NodeType.REF_DOT_EXPR && isImportMeta(n)) {\n                    throw new ParserException(\"invalid \" + siteName + \": import.meta\");\n                }\n            }\n            case FN_CALL_EXPR -> {\n                // Web-compat carve-out (Annex B B.3.5): allow `f() = 1` in non-strict mode.\n                // Logical-assignment operators (||=, &&=, ??=) are ES2021 and the carve-out\n                // does NOT apply to them; the caller passes noCallCarveOut=true in that case.\n                if (noCallCarveOut) {\n                    throw new ParserException(\"invalid \" + siteName + \": call expression\");\n                }\n            }\n            default ->\n                    throw new ParserException(\"invalid \" + siteName + \": \"\n                            + n.type.name() + \" is not a valid assignment target\");\n        }\n    }\n\n    /**\n     * Strip thin {@code EXPR} / {@code EXPR_LIST} single-child wrappers introduced","sourceCodeStart":1716,"sourceCodeEnd":1752,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/parser/JsParser.java#L1716-L1752","documentation":"`import.meta` is a meta-property with an invalid AssignmentTargetType per the ES spec, so it cannot be assigned to. Because Karate's lexer does not reserve `import`, this shape parses as a plain REF_DOT_EXPR and is explicitly rejected during assignment-target validation.","triggerScenarios":"Code like `import.meta = x`, `[import.meta] = arr`, or destructuring `({url: import.meta} = o)` where `import.meta` appears in a target position.","commonSituations":"Misreading `import.meta` as a mutable object; trying to monkey-patch meta information; generated code attempting to write to meta.","solutions":["Read from `import.meta` only; never assign to it","Copy the desired meta value into a variable first, then mutate the variable","If you need custom metadata, store it in your own module-level object instead"],"exampleFix":"// before\nimport.meta.url = otherUrl;\n// after\nconst myUrl = import.meta.url;\n// mutate myUrl or your own config object instead","handlingStrategy":"validation","validationCode":"if (/import\\.meta\\s*=[^=]/.test(code) || /\\[\\s*import\\.meta\\s*\\]/.test(code)) {\n  throw new Error('import.meta is not assignable');\n}","typeGuard":"function assignsImportMeta(node) {\n  return (node.type === 'AssignmentExpression' || node.type === 'UpdateExpression') &&\n    JSON.stringify(node.left).includes('import.meta');\n}","tryCatchPattern":"try {\n  karate.eval(code);\n} catch (e) {\n  if (String(e.message).includes('import.meta')) { /* copy to variable first */ }\n  throw e;\n}","preventionTips":["Treat import.meta as strictly read-only","Copy meta values into local variables before mutating","Lint generated code for import.meta in target positions"],"tags":["javascript","parser","import-meta","assignment-target"],"backgroundTag":"invalid-argument-value","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}