{"record":{"id":"61c62197c4519f60","repo":"vitest-dev/vitest","slug":"vi-dounmock-expects-a-string-path-but-received-61c621","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/vitest/src/integrations/vi.ts","lineNumber":711,"sourceCode":"                  importer,\n                  _mocker().getMockContext().callstack,\n                ),\n              )\n          : factory,\n      )\n\n      const rv = {} as Disposable\n      if (Symbol.dispose) {\n        rv[Symbol.dispose] = () => {\n          _mocker().queueUnmock(path, importer)\n        }\n      }\n      return rv\n    },\n\n    doUnmock(path: string | Promise<unknown>) {\n      if (typeof path !== 'string') {\n        throw new TypeError(\n          `vi.doUnmock() expects a string path, but received a ${typeof path}`,\n        )\n      }\n      const importer = getImporter('doUnmock')\n      _mocker().queueUnmock(path, importer)\n    },\n\n    async importActual<T = unknown>(path: string): Promise<T> {\n      const importer = getImporter('importActual')\n      return _mocker().importActual<T>(\n        path,\n        importer,\n        _mocker().getMockContext().callstack,\n      )\n    },\n\n    async importMock<T>(path: string): Promise<MaybeMockedDeep<T>> {\n      const importer = getImporter('importMock')","sourceCodeStart":693,"sourceCodeEnd":729,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/integrations/vi.ts#L693-L729","documentation":"Thrown by `vi.doUnmock(path)` when `path` is not a string. `vi.doUnmock` is the non-hoisted counterpart to `vi.unmock` and requires a string module specifier so the mocker can queue the unmock against the importer's call stack. Any non-string argument raises a TypeError.","triggerScenarios":"Calling `vi.doUnmock(nonString)`; passing an imported module namespace, a Promise, or a number; using a variable that is undefined at call time.","commonSituations":"Pairing `vi.doMock` with `vi.doUnmock` but passing the wrong argument type; refactoring that drops the literal path; misunderstanding the required specifier form.","solutions":["Pass a string specifier: `vi.doUnmock('./myModule')`.","Verify the argument is a string at call time when computed dynamically.","Ensure you pass the path string, not the imported binding."],"exampleFix":"// before\nimport * as M from './myModule'\nvi.doUnmock(M)\n\n// after\nvi.doUnmock('./myModule')","handlingStrategy":"type-guard","validationCode":"function doUnmockSafe(path) {\n  if (typeof path !== 'string') throw new TypeError('vi.doUnmock requires a string path')\n  return vi.doUnmock(path)\n}","typeGuard":"function isModulePath(v): v is string {\n  return typeof v === 'string' && v.length > 0\n}","tryCatchPattern":null,"preventionTips":["Pass a string specifier to vi.doUnmock.","Verify dynamically computed paths are strings at call time.","Do not pass imported module objects as the path argument."],"tags":["vi-dounmock","type-error","module-path","dynamic-mocking"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}