{"record":{"id":"d089461bdc8a2ed6","repo":"vitest-dev/vitest","slug":"vi-unmock-expects-a-string-path-but-received-a-d08946","errorCode":null,"errorMessage":"vi.unmock() expects a string path, but received a ${typeof path}","messagePattern":"vi\\.unmock\\(\\) expects a string path, but received a (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/integrations/vi.ts","lineNumber":671,"sourceCode":"      _mocker().queueMock(\n        path,\n        importer,\n        typeof factory === 'function'\n          ? () =>\n              factory(() =>\n                _mocker().importActual(\n                  path,\n                  importer,\n                  _mocker().getMockContext().callstack,\n                ),\n              )\n          : factory,\n      )\n    },\n\n    unmock(path: string | Promise<unknown>) {\n      if (typeof path !== 'string') {\n        throw new TypeError(\n          `vi.unmock() expects a string path, but received a ${typeof path}`,\n        )\n      }\n      _mocker().queueUnmock(path, getImporter('unmock'))\n    },\n\n    doMock(path: string | Promise<unknown>, factory?: MockOptions | MockFactoryWithHelper) {\n      if (typeof path !== 'string') {\n        throw new TypeError(\n          `vi.doMock() expects a string path, but received a ${typeof path}`,\n        )\n      }\n      const importer = getImporter('doMock')\n      _mocker().queueMock(\n        path,\n        importer,\n        typeof factory === 'function'\n          ? () =>","sourceCodeStart":653,"sourceCodeEnd":689,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/integrations/vi.ts#L653-L689","documentation":"Thrown by `vi.unmock(path)` when `path` is not a string. Like `vi.mock`, `vi.unmock` is hoisted and requires a string module specifier so the transformer can register the unmock before imports execute. A non-string path is rejected with a TypeError.","triggerScenarios":"Calling `vi.unmock(nonString)`; passing a module namespace object or Promise instead of a path string; using a dynamically computed path that isn't a string.","commonSituations":"Refactoring that replaces a literal path with a variable; passing the imported binding; misunderstanding the hoisting requirement; copy-paste from `vi.mock` with the wrong argument.","solutions":["Pass a string literal specifier: `vi.unmock('./myModule')`.","If you need runtime control, use `vi.doUnmock` inside the test (still requires a string).","Verify the argument is the specifier, not the imported module object."],"exampleFix":"// before\nimport * as M from './myModule'\nvi.unmock(M)\n\n// after\nvi.unmock('./myModule')","handlingStrategy":"type-guard","validationCode":"function unmockSafe(path) {\n  if (typeof path !== 'string') throw new TypeError('vi.unmock requires a string path')\n  return vi.unmock(path)\n}","typeGuard":"function isModulePath(v): v is string {\n  return typeof v === 'string' && v.length > 0\n}","tryCatchPattern":null,"preventionTips":["Pass a string literal specifier to vi.unmock.","Avoid passing imported bindings as the path.","Use vi.doUnmock for non-hoisted, runtime-controlled unmocking."],"tags":["vi-unmock","hoisting","type-error","module-path"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}