{"record":{"id":"e669aa309c9aaebf","repo":"parcel-bundler/parcel","slug":"failed-to-parse-path-basename-configfile","errorCode":null,"errorMessage":"Failed to parse ${path.basename(configFile)}","messagePattern":"Failed to parse (.+?)","errorType":"exception","errorClass":"ThrowableDiagnostic","httpStatus":null,"severity":"error","filePath":"packages/core/utils/src/config.js","lineNumber":134,"sourceCode":"    let config;\n    if (parse === false) {\n      config = configContent;\n    } else {\n      let extname = path.extname(configFile).slice(1);\n      let parse = opts?.parser ?? getParser(extname);\n      try {\n        config = parse(configContent);\n      } catch (e) {\n        if (extname !== '' && extname !== 'json') {\n          throw e;\n        }\n\n        let pos = {\n          line: e.lineNumber,\n          column: e.columnNumber,\n        };\n\n        throw new ThrowableDiagnostic({\n          diagnostic: {\n            message: `Failed to parse ${path.basename(configFile)}`,\n            origin: '@parcel/utils',\n            codeFrames: [\n              {\n                language: 'json5',\n                filePath: configFile,\n                code: configContent,\n                codeHighlights: [\n                  {\n                    start: pos,\n                    end: pos,\n                    message: e.message,\n                  },\n                ],\n              },\n            ],\n          },","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/core/utils/src/config.js#L116-L152","documentation":"Thrown by @parcel/utils readConfig when a JSON/JSON5 config file fails to parse. Only raised for files with a .json extension or no extension (JSON5-style files); other extensions rethrow the original parser error unwrapped. The ThrowableDiagnostic includes a code frame pinpointing e.lineNumber/e.columnNumber.","triggerScenarios":"Parcel loads a .parcelrc, .eslintrc, tsconfig.json, or other JSON config that contains a syntax error (trailing comma, unquoted key, single quotes, unclosed brace) and the registered parser throws.","commonSituations":"Hand-editing JSON and introducing a trailing comma or comment; copying JSON5 syntax into a strict .json file; BOM/encoding issues; git merge conflicts leaving conflict markers in the config.","solutions":["Open the file named in the message and fix the syntax at the reported line/column.","Validate the file with `node -e \"JSON.parse(require('fs').readFileSync('FILE','utf8'))\"` (for strict JSON).","Rename to .json5 / .jsonc if you intentionally use comments/trailing commas and ensure the right parser is registered.","Remove git merge conflict markers or BOM before re-running."],"exampleFix":"// before — .eslintrc.json (invalid: trailing comma)\n{\n  \"extends\": [\"parcel\"],\n}\n\n// after\n{\n  \"extends\": [\"parcel\"]\n}","handlingStrategy":"validation","validationCode":"// Validate a JSON config before passing it to Parcel.\nconst fs = require('fs');\nfunction validateJsonConfig(file) {\n  const txt = fs.readFileSync(file, 'utf8');\n  try { JSON.parse(txt); }\n  catch (e) { throw new Error(`${file} is invalid JSON: ${e.message}`); }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const cfg = await readConfig(fs, configFile);\n} catch (e) {\n  if (e?.diagnostic?.message?.startsWith('Failed to parse')) {\n    // surface the code frame, prompt user to fix the file\n  } else throw e;\n}","preventionTips":["Lint JSON configs in CI with a JSON parser before build.","Use .jsonc/.json5 explicitly when you need comments/trailing commas and register the matching parser.","Add editor schema validation for .parcelrc/tsconfig etc."],"tags":["config","json","json5","parse-error"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}