{"record":{"id":"e8d18b00a93d26c7","repo":"parcel-bundler/parcel","slug":"scope-hoisting-cannot-be-disabled-for-library-targ","errorCode":null,"errorMessage":"Scope hoisting cannot be disabled for library targets.","messagePattern":"Scope hoisting cannot be disabled for library targets\\.","errorType":"exception","errorClass":"ThrowableDiagnostic","httpStatus":null,"severity":"error","filePath":"packages/core/core/src/requests/TargetRequest.js","lineNumber":866,"sourceCode":"                  ]),\n                },\n              ],\n              hints: [\n                `Either change the output file extension to .mjs, add \"type\": \"module\" to package.json, or remove the declared outputFormat.`,\n              ],\n              documentationURL:\n                'https://parceljs.org/features/targets/#library-targets',\n            },\n          });\n        }\n\n        if (descriptor.scopeHoist === false) {\n          let contents: string =\n            typeof pkgContents === 'string'\n              ? pkgContents\n              : // $FlowFixMe\n                JSON.stringify(pkgContents, null, '\\t');\n          throw new ThrowableDiagnostic({\n            diagnostic: {\n              message: 'Scope hoisting cannot be disabled for library targets.',\n              origin: '@parcel/core',\n              codeFrames: [\n                {\n                  language: 'json',\n                  filePath: pkgFilePath ?? undefined,\n                  code: contents,\n                  codeHighlights: generateJSONCodeHighlights(contents, [\n                    {\n                      key: `/targets/${targetName}/scopeHoist`,\n                      type: 'value',\n                    },\n                  ]),\n                },\n              ],\n              hints: [\n                `The \"${targetName}\" target is meant for libraries. Either remove the \"scopeHoist\" option, or use a different target name.`,","sourceCodeStart":848,"sourceCodeEnd":884,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/core/core/src/requests/TargetRequest.js#L848-L884","documentation":"Library targets must be scope-hoisted because their output is consumed by other tooling and must be a single flattened module graph. This guard (in the COMMON_TARGETS descriptor path) throws when `descriptor.scopeHoist === false` is set explicitly on a library target. The diagnostic highlights /targets/<name>/scopeHoist in package.json.","triggerScenarios":"Setting `\"scopeHoist\": false` under a common library target (main/module/types) in package.json.","commonSituations":"Disabling scope hoisting globally to debug a tree-shaking issue and forgetting to re-enable for library builds; copying app-only options into a library target; trying to reduce build time by skipping scope hoisting on a published package.","solutions":["Remove `\"scopeHoist\": false` from the library target.","Set `\"scopeHoist\": true` (or omit it) for the library target.","If you genuinely need non-hoisted output, build as an application target instead of a library."],"exampleFix":"// before (package.json)\n\"targets\": {\n  \"main\": { \"isLibrary\": true, \"scopeHoist\": false }\n}\n\n// after\n\"targets\": {\n  \"main\": { \"isLibrary\": true }\n}","handlingStrategy":"validation","validationCode":"function assertLibraryScopeHoist(targets) {\n  for (const [name, d] of Object.entries(targets || {})) {\n    if (d.isLibrary && d.scopeHoist === false) {\n      throw new Error(`Target ${name} is a library and cannot disable scope hoisting.`);\n    }\n  }\n}","typeGuard":"function isLibraryScopeHoistValid(d) {\n  return !(d?.isLibrary === true && d?.scopeHoist === false);\n}","tryCatchPattern":"try { await parcel.run(); } catch (e) {\n  if (/Scope hoisting cannot be disabled for library targets/.test(e.message)) {\n    console.error('Remove scopeHoist:false from library targets.');\n  } else throw e;\n}","preventionTips":["Never set `scopeHoist: false` on library targets.","Keep scope-hoist settings on app targets only.","Validate target descriptors before invoking Parcel."],"tags":["parcel","targets","scope-hoisting","library","config"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}