{"record":{"id":"ac14707147b447d5","repo":"swc-project/swc","slug":"duplicated-methods-element-key-can-t-be-decor","errorCode":null,"errorMessage":"Duplicated methods (${element.key}) can't be decorated.","messagePattern":"Duplicated methods \\((.+?)\\) can't be decorated\\.","errorType":"exception","errorClass":"ReferenceError","httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_base/src/helpers/generated/_decorate.rs","lineNumber":56,"sourceCode":"}\nfunction _coalesceGetterSetter(element, other) {\n    if (element.descriptor.get !== undefined) other.descriptor.get = element.descriptor.get;\n    else other.descriptor.set = element.descriptor.set;\n}\nfunction _coalesceClassElements(elements) {\n    var newElements = [];\n    var isSameElement = function isSameElement(other) {\n        return other.kind === \"method\" && other.key === element.key && other.placement === element.placement;\n    };\n\n    for (var i = 0; i < elements.length; i++) {\n        var element = elements[i];\n        var other;\n\n        if (element.kind === \"method\" && (other = newElements.find(isSameElement))) {\n            if (_isDataDescriptor(element.descriptor) || _isDataDescriptor(other.descriptor)) {\n                if (_hasDecorators(element) || _hasDecorators(other)) {\n                    throw new ReferenceError(\"Duplicated methods (\" + element.key + \") can't be decorated.\");\n                }\n                other.descriptor = element.descriptor;\n            } else {\n                if (_hasDecorators(element)) {\n                    if (_hasDecorators(other)) {\n                        throw new ReferenceError(\"Decorators can't be placed on different accessors with for \" + \"the same property (\" + element.key + \").\");\n                    }\n                    other.decorators = element.decorators;\n                }\n                _coalesceGetterSetter(element, other);\n            }\n        } else {\n            newElements.push(element);\n        }\n    }\n\n    return newElements;\n}","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_base/src/helpers/generated/_decorate.rs#L38-L74","documentation":"The napi `parseFileSync(path, opts)` function loads the JS/TS file from disk via SourceMap::load_file and unwraps it with .expect(\"failed to read program file\"). Any I/O failure - missing path, permission denied, or content the loader cannot handle - becomes a Rust panic that napi-rs reports to JS as an exception with this message. Unlike parse errors, nothing is captured by the swc handler because the panic happens before parsing starts.","triggerScenarios":"Calling parseFileSync('src/foo.ts', opts) where the file does not exist, is a directory, has no read permission, or the path is relative to a different working directory than assumed (the Rust side resolves it from the process cwd).","commonSituations":"Bundlers or CLIs run from a different cwd so a relative path resolves wrong; globs that include deleted files; permission-restricted mount or Docker volume without read access; case-sensitive filesystem mismatches after cloning a repo from Windows.","solutions":["Verify the path before calling: use fs.existsSync / fs.statSync and resolve it to an absolute path with path.resolve.","Check file readability (fs.accessSync(p, fs.constants.R_OK)) and fix permissions if needed.","Prefer the buffer-based parse API (parseSync with source text) when you already have the contents in memory, avoiding filesystem coupling entirely.","Wrap the call in try/catch and surface the JS exception message - it contains the path context from the panic."],"exampleFix":"// before: panics inside Rust when the file is missing\nconst out = parseFileSync('src/app.ts', opts);\n\n// after: validate first, then call\nconst file = path.resolve('src/app.ts');\nfs.accessSync(file, fs.constants.R_OK);\nconst out = parseFileSync(file, opts);","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nimport path from 'node:path';\n\nfunction parseFileSyncSafe(relPath, opts) {\n  const file = path.resolve(relPath); // cwd-independent\n  const st = fs.statSync(file); // throws ENOENT/EACCES with a clear JS error\n  if (!st.isFile()) throw new Error(`not a file: ${file}`);\n  fs.accessSync(file, fs.constants.R_OK);\n  return parseFileSync(file, opts);\n}","typeGuard":"function isReadableFile(p: string): boolean {\n  try {\n    return fs.statSync(p).isFile();\n  } catch {\n    return false;\n  }\n}","tryCatchPattern":"try {\n  result = parseFileSync(file, opts);\n} catch (e) {\n  if (/failed to read program file/.test(String(e?.message))) {\n    throw new Error(`swc could not read ${file}: check the path and permissions`, { cause: e });\n  }\n  throw e;\n}","preventionTips":["Resolve every path against an explicit base directory; never rely on process.cwd in tools.","When the source is already in memory, use the source-text parse API instead of the file variant.","In watch/build pipelines, handle delete events by removing files from the worklist before parsing."],"tags":["swc","napi","file-io","node-bindings","panic","path"],"backgroundTag":"file-not-found","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}