{"id":"802f621e1300a5a2","repo":"jestjs/jest","slug":"the-first-argument-to-require-resolve-paths-must-n","errorCode":null,"errorMessage":"The first argument to require.resolve.paths must not be the empty string.","messagePattern":"The first argument to require\\.resolve\\.paths must not be the empty string\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-runtime/src/internals/cjsRequire.ts","lineNumber":183,"sourceCode":"      if (module) {\n        return module;\n      }\n      throw error;\n    }\n  }\n\n  private resolvePaths(\n    from: string,\n    moduleName: string | undefined,\n  ): Array<string> | null {\n    const fromDir = path.resolve(from, '..');\n    if (moduleName == null) {\n      throw new Error(\n        'The first argument to require.resolve.paths must be a string. Received null or undefined.',\n      );\n    }\n    if (moduleName.length === 0) {\n      throw new Error(\n        'The first argument to require.resolve.paths must not be the empty string.',\n      );\n    }\n\n    if (moduleName[0] === '.') {\n      return [fromDir];\n    }\n    if (this.resolution.isCoreModule(moduleName)) {\n      return null;\n    }\n    const modulePaths = this.resolution.getModulePaths(fromDir);\n    const globalPaths = this.resolution.getGlobalPaths(moduleName);\n    return [...modulePaths, ...globalPaths];\n  }\n}\n\nexport interface CoreModuleProviderOptions {\n  resolution: Resolution;","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-runtime/src/internals/cjsRequire.ts#L165-L201","documentation":"Thrown by `RequireBuilder.resolvePaths` (cjsRequire.ts:182-186) when `require.resolve.paths('')` is called. An empty string can't be a module name and would produce nonsense search paths, so the runtime rejects it explicitly after the null check.","triggerScenarios":"`require.resolve.paths('')`, or a variable that was trimmed/sanitized down to empty. Programmatically built names that collapse to empty under some inputs.","commonSituations":"Parsing logic that strips prefixes and yields empty for certain inputs. Copy-paste from a config that had a placeholder.","solutions":["Validate `name.length > 0` before calling.","Fix the upstream code that produced an empty module name.","Treat empty as a no-op rather than passing it through."],"exampleFix":"// before\nrequire.resolve.paths(name.trim()); // throws if name is whitespace-only\n\n// after\nconst trimmed = name.trim();\nif (trimmed.length > 0) require.resolve.paths(trimmed);","handlingStrategy":"validation","validationCode":"if (typeof name !== 'string' || name.trim().length === 0) {\n  throw new Error('require.resolve.paths needs a non-empty string');\n}\nrequire.resolve.paths(name);","typeGuard":"function isNonEmptyString(v: unknown): v is string {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":null,"preventionTips":["Sanitize and validate names derived from user input or parsed strings before passing them in.","Add unit tests for empty/whitespace inputs to your resolution helpers."],"tags":["require-resolve","validation","empty-string"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}