{"id":"a77a1883728be099","repo":"jestjs/jest","slug":"cannot-define-a-method-called-name","errorCode":null,"errorMessage":"Cannot define a method called ${name}","messagePattern":"Cannot define a method called (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/jest-worker/src/index.ts","lineNumber":148,"sourceCode":"        workerSchedulingPolicy: this._options.workerSchedulingPolicy,\n      },\n    );\n\n    this._bindExposedWorkerMethods(workerPath, this._options);\n  }\n\n  private _bindExposedWorkerMethods(\n    workerPath: string,\n    options: WorkerFarmOptions,\n  ): void {\n    for (const name of getExposedMethods(workerPath, options)) {\n      if (name.startsWith('_')) {\n        continue;\n      }\n\n      // eslint-disable-next-line no-prototype-builtins\n      if (this.constructor.prototype.hasOwnProperty(name)) {\n        throw new TypeError(`Cannot define a method called ${name}`);\n      }\n\n      // @ts-expect-error: dynamic extension of the class instance is expected.\n      this[name] = this._callFunctionWithArgs.bind(this, name);\n    }\n  }\n\n  private _callFunctionWithArgs(\n    method: string,\n    ...args: Array<unknown>\n  ): Promise<unknown> {\n    if (this._ending) {\n      throw new Error('Farm is ended, no more calls can be done to it');\n    }\n\n    return this._farm.doWork(method, ...args);\n  }\n","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-worker/src/index.ts#L130-L166","documentation":"Error \"Cannot define a method called ${name}\" thrown in jestjs/jest.","triggerScenarios":"Thrown at packages/jest-worker/src/index.ts:148 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not expose a method whose name collides with reserved/internal names on the jest-worker farm. Rename the method you are trying to define on the worker to a non-conflicting name."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}