{"record":{"id":"0ede60c5c0032e65","repo":"vitest-dev/vitest","slug":"vi-dounmock-expects-a-string-path-but-received","errorCode":null,"errorMessage":"vi.doUnmock() expects a string path, but received a ${typeof path}","messagePattern":"vi\\.doUnmock\\(\\) expects a string path, but received a (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/mocker/src/browser/hints.ts","lineNumber":117,"sourceCode":"      const importer = getImporter('doMock')\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    doUnmock(path: string | Promise<unknown>): void {\n      if (typeof path !== 'string') {\n        throw new TypeError(\n          `vi.doUnmock() expects a string path, but received a ${typeof path}`,\n        )\n      }\n      _mocker().queueUnmock(path, getImporter('doUnmock'))\n    },\n\n    async importActual<T = unknown>(path: string): Promise<T> {\n      return _mocker().importActual<T>(\n        path,\n        getImporter('importActual'),\n      )\n    },\n\n    async importMock<T>(path: string): Promise<MaybeMockedDeep<T>> {\n      return _mocker().importMock(path, getImporter('importMock'))\n    },\n  }\n}","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/mocker/src/browser/hints.ts#L99-L135","documentation":"`vi.doUnmock(path)` is the non-hoisted counterpart of `vi.unmock` and also requires a string path. A non-string argument triggers a `TypeError` (with `typeof path`) before the unmock is queued in the browser mocker.","triggerScenarios":"Calling `vi.doUnmock(moduleNamespace)`, `vi.doUnmock(42)`, or any non-string identifier.","commonSituations":"Passing the imported module object instead of its path; refactor that swapped in a non-string; mixing hoisted and non-hoisted forms with mismatched argument types.","solutions":["Pass the path string matching a prior `vi.doMock`: `vi.doUnmock('./db')`.","Verify the argument type when the path is dynamic.","Distinguish from `vi.unmock` (hoisted) which also requires a string."],"exampleFix":"// before\nvi.doUnmock(dbNamespace)\n\n// after\nvi.doUnmock('./db')","handlingStrategy":"type-guard","validationCode":"if (typeof path !== 'string') {\n  throw new TypeError(`vi.doUnmock requires a string path, got ${typeof path}`)\n}","typeGuard":"const isPathString = (v: unknown): v is string => typeof v === 'string'","tryCatchPattern":null,"preventionTips":["Pass a string path matching a prior vi.doMock to vi.doUnmock.","Do not pass the imported namespace object.","Keep doMock/doUnmock argument types consistent."],"tags":["mocker","vi-dounmock","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"}