{"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/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/integrations/vi.ts#L653-L689","documentation":"`vi.unmock(path)` is the counterpart of `vi.mock`, removing a previously queued mock for the given string module path. Like `vi.mock`, it rejects non-string `path` values with a `TypeError` because the mocker can only look up mocks by resolved string path. The signature types `path` as `string | Promise<unknown>` but enforces string at runtime.","triggerScenarios":"Calling `vi.unmock(123)`, `vi.unmock(someObject)`, `vi.unmock(import('./mod'))`, or `vi.unmock(undefined)`.","commonSituations":"Passing a module namespace or promise instead of the specifier string, or a variable that resolved to a non-string.","solutions":["Pass the module specifier as a literal string: `vi.unmock('./api')`.","Ensure any dynamic path variable is a string before calling.","Use `vi.doUnmock` with a runtime string for non-literal paths."],"exampleFix":"// before\nvi.unmock(import('./api'))\n// after\nvi.unmock('./api')","handlingStrategy":"type-guard","validationCode":"function unmockPath(path: unknown) {\n  if (typeof path !== 'string') throw new TypeError(`vi.unmock expects string, got ${typeof path}`)\n  vi.unmock(path)\n}","typeGuard":"function isModulePath(v: unknown): v is string { return typeof v === 'string' && v.length > 0 }","tryCatchPattern":null,"preventionTips":["Always pass a string literal module specifier to `vi.unmock`.","Use `vi.doUnmock` for runtime-computed string paths."],"tags":["mock","vi-mock","type-error","validation"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}