{"record":{"id":"fee627b5dec8f60c","repo":"parcel-bundler/parcel","slug":"origin-must-be-an-absolute-path","errorCode":null,"errorMessage":"`origin` must be an absolute path","messagePattern":"`origin` must be an absolute path","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/dev/eslint-plugin/src/utils.js","lineNumber":65,"sourceCode":"    node.arguments &&\n    node.arguments[0] &&\n    typeof node.arguments[0].value === 'string' &&\n    node.arguments[0].value.trim()\n  );\n}\n\n/**\n * Like path.relative, but for determining relative path between a filepath and\n * a module it requests in a `require`.\n * @param {Object} opts\n * @param {string} opts.origin - Originating file. Must be an absolute path.\n * @param {string} opts.request - Requested module in the require. e.g. @parcel/core\n * @param {string} opts.pkgName - name of the package in the package json\n * @param {string} opts.pkgPath - path to the package.json\n */\nfunction relativePathForRequire({origin, request, pkgName, pkgPath}) {\n  if (!path.isAbsolute(origin)) {\n    throw new TypeError('`origin` must be an absolute path');\n  }\n\n  if (path.isAbsolute(request)) {\n    return request;\n  }\n\n  const pkgRoot = path.dirname(pkgPath);\n  let relative = path\n    .relative(\n      path.dirname(origin),\n      request.replace(new RegExp('^' + pkgName), pkgRoot),\n    )\n    // `require` expects unix-style '/' separators, but `path.relative` will respect\n    // `path.sep`.\n    .split(path.sep)\n    .join('/');\n\n  // prefer `require('../')` over `require('..')`","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/dev/eslint-plugin/src/utils.js#L47-L83","documentation":"Thrown by relativePathForRequire in eslint-plugin/@parcel dev utils when opts.origin is not an absolute path. The function computes the relative path from the originating file to a required module and assumes origin is absolute; a relative origin would produce wrong results, so it rejects with a TypeError.","triggerScenarios":"Calling relativePathForRequire({ origin: './src/file.js', ... }) — i.e. the eslint rule helper is invoked with a relative originating file path instead of an absolute one.","commonSituations":"Custom eslint rules built on @parcel/eslint-plugin utils passing __filename-relative paths; mock/test harnesses that synthesize relative origins; refactors that dropped a path.resolve() call.","solutions":["Pass an absolute path for origin: `path.resolve(origin)` before calling.","Ensure upstream callers (eslint context.getFilename()) provide absolute paths — they normally do.","Add a guard: `if (!path.isAbsolute(origin)) origin = path.resolve(process.cwd(), origin);`."],"exampleFix":"// before\nrelativePathForRequire({ origin: 'src/file.js', request, pkgName, pkgPath });\n\n// after\nrelativePathForRequire({\n  origin: path.resolve('src/file.js'),\n  request, pkgName, pkgPath,\n});","handlingStrategy":"validation","validationCode":"const path = require('path');\nfunction relativePathForRequireSafe(opts) {\n  const origin = path.isAbsolute(opts.origin) ? opts.origin : path.resolve(opts.origin);\n  return relativePathForRequire({ ...opts, origin });\n}","typeGuard":"function isAbsolutePath(p: string): boolean {\n  return typeof p === 'string' && path.isAbsolute(p);\n}","tryCatchPattern":null,"preventionTips":["Always pass absolute paths to relativePathForRequire; wrap with path.resolve at the call site.","Trust eslint context.getFilename() (absolute by contract) and avoid overriding it with relative strings.","Add a unit test asserting origin is absolute before invoking the helper."],"tags":["eslint-plugin","paths","validation","dev-tools"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}