{"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":"validation","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/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/mocker/src/browser/hints.ts#L99-L135","documentation":"Thrown at packages/mocker/src/browser/hints.ts:116-119 as a TypeError when vi.doUnmock() is called with a non-string first argument. vi.doUnmock is the non-hoisted counterpart of vi.unmock and needs a string specifier to remove a mock from the registry at call time.","triggerScenarios":"Calling vi.doUnmock(undefined), vi.doUnmock(someVar) where someVar is not a string, or vi.doUnmock(import('./x')) that escaped transform rewriting.","commonSituations":"Refactoring unmock calls to doUnmock and dropping the path; passing a computed value that is not a string.","solutions":["Pass a string literal module path: vi.doUnmock('./logger').","Validate any dynamic path is a string before calling."],"exampleFix":"// before\nvi.doUnmock(import('./logger'))\n\n// after\nvi.doUnmock('./logger')","handlingStrategy":"type-guard","validationCode":"function doUnmockIfString(path: unknown) {\n  if (typeof path !== 'string') {\n    throw new TypeError(`vi.doUnmock requires a string path, got ${typeof path}`)\n  }\n  vi.doUnmock(path)\n}","typeGuard":"function isModulePath(path: unknown): path is string {\n  return typeof path === 'string' && path.length > 0\n}","tryCatchPattern":null,"preventionTips":["Pass a string literal module specifier to vi.doUnmock.","Validate dynamically computed paths are strings before calling."],"tags":["vi-dounmock","type-validation","typeerror","module-path"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}