{"record":{"id":"407dd449f5f5e592","repo":"parcel-bundler/parcel","slug":"parcel-is-already-profiling","errorCode":null,"errorMessage":"Parcel is already profiling","messagePattern":"Parcel is already profiling","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/core/src/Parcel.js","lineNumber":450,"sourceCode":"          this.#watchQueue.run();\n        }\n      },\n      opts,\n    );\n    return {unsubscribe: () => sub.unsubscribe()};\n  }\n\n  // This is mainly for integration tests and it not public api!\n  _getResolvedParcelOptions(): ParcelOptions {\n    return nullthrows(\n      this.#resolvedOptions,\n      'Resolved options is null, please let parcel initialize before accessing this.',\n    );\n  }\n\n  async startProfiling(): Promise<void> {\n    if (this.isProfiling) {\n      throw new Error('Parcel is already profiling');\n    }\n\n    logger.info({origin: '@parcel/core', message: 'Starting profiling...'});\n    this.isProfiling = true;\n    await this.#farm.startProfile();\n  }\n\n  stopProfiling(): Promise<void> {\n    if (!this.isProfiling) {\n      throw new Error('Parcel is not profiling');\n    }\n\n    logger.info({origin: '@parcel/core', message: 'Stopping profiling...'});\n    this.isProfiling = false;\n    return this.#farm.endProfile();\n  }\n\n  takeHeapSnapshot(): Promise<void> {","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/core/core/src/Parcel.js#L432-L468","documentation":"`startProfiling` is a one-shot toggle guarded by the `isProfiling` flag. Parcel only allows one active profiling session per instance because the underlying worker farm profile is a single resource. Calling start while already running would corrupt the trace.","triggerScenarios":"Calling `parcel.startProfiling()` twice without an intervening `stopProfiling()`.","commonSituations":"Test harnesses or scripts that start profiling on each build without stopping; retry logic that re-invokes start.","solutions":["Call `await parcel.stopProfiling()` before starting again.","Guard with `if (!parcel.isProfiling)` before calling start.","Restructure the caller to start/stop exactly once per profiled run."],"exampleFix":"// before\nawait parcel.startProfiling();\nawait parcel.startProfiling();\n\n// after\nif (!parcel.isProfiling) await parcel.startProfiling();","handlingStrategy":"validation","validationCode":"// Guard start against an in-flight session.\nif (!parcel.isProfiling) await parcel.startProfiling();","typeGuard":"function canStartProfiling(p: {isProfiling: boolean}): boolean {\n  return p.isProfiling === false;\n}","tryCatchPattern":null,"preventionTips":["Centralize profiling start/stop in one place.","Always pair start with a stop in a finally block (but guard the stop).","Reuse the `isProfiling` flag rather than tracking your own."],"tags":["profiling","lifecycle"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}