{"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":"validation","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/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/mocker/src/browser/hints.ts#L68-L104","documentation":"Thrown at packages/mocker/src/browser/hints.ts:85-89 as a TypeError when vi.unmock() receives a non-string first argument. vi.unmock queues removal of a mock by module specifier, so the path must be a string to look up in the registry.","triggerScenarios":"Calling vi.unmock(undefined), vi.unmock(someVar) with a non-string variable, or vi.unmock(import('./x')) that was not rewritten.","commonSituations":"Calling unmock with the wrong argument type after refactoring; passing an object/number accidentally; dynamic import not rewritten by transform.","solutions":["Pass a string literal module path: vi.unmock('./logger').","Ensure any variable passed is a string at runtime."],"exampleFix":"// before\nvi.unmock(config.loggerPath)\n\n// after\nvi.unmock('./logger')","handlingStrategy":"type-guard","validationCode":"function unmockIfString(path: unknown) {\n  if (typeof path !== 'string') {\n    throw new TypeError(`vi.unmock requires a string path, got ${typeof path}`)\n  }\n  vi.unmock(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.unmock.","Keep path variables strongly typed as string."],"tags":["vi-unmock","type-validation","typeerror","module-path"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}