{"record":{"id":"2c229f575a556f5c","repo":"vitest-dev/vitest","slug":"vi-unmock-expects-a-string-path-but-received-a","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/mocker/src/browser/hints.ts","lineNumber":86,"sourceCode":"      const importer = getImporter('mock')\n      _mocker().queueMock(\n        path,\n        importer,\n        typeof factory === 'function'\n          ? () =>\n              factory(() =>\n                _mocker().importActual(\n                  path,\n                  importer,\n                ),\n              )\n          : factory,\n      )\n    },\n\n    unmock(path: string | Promise<unknown>): void {\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?: ModuleMockOptions | ModuleMockFactoryWithHelper): void {\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":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/mocker/src/browser/hints.ts#L68-L104","documentation":"`vi.unmock(path)` removes a previously registered mock and requires a string path to identify the module. Passing a non-string triggers a `TypeError` (with `typeof path`) before the unmock is queued.","triggerScenarios":"Calling `vi.unmock(importedModule)`, `vi.unmock(42)`, or any non-string value as the path argument.","commonSituations":"Passing the imported namespace object instead of the path string; refactor that changed the argument; mismatched mock/unmock argument types in a setup file.","solutions":["Pass the same string path used in `vi.mock`: `vi.unmock('./db')`.","Confirm the variable is a string when path is dynamic.","Distinguish from `vi.doUnmock` which also takes a string but is not hoisted."],"exampleFix":"// before\nvi.unmock(dbModule)\n\n// after\nvi.unmock('./db')","handlingStrategy":"type-guard","validationCode":"if (typeof path !== 'string') {\n  throw new TypeError(`vi.unmock requires a string path, got ${typeof path}`)\n}","typeGuard":"const isPathString = (v: unknown): v is string => typeof v === 'string'","tryCatchPattern":null,"preventionTips":["Pass the same string path used in vi.mock to vi.unmock.","Do not pass the imported namespace object.","Keep mock/unmock argument types consistent in setup files."],"tags":["mocker","vi-unmock","type-error","browser"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}