{"id":"69ba3144bccc7281","repo":"babel/babel","slug":"cannot-use-internal-helper-name","errorCode":null,"errorMessage":"Cannot use internal helper ${name}","messagePattern":"Cannot use internal helper (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/babel-core/src/transformation/file/file.ts","lineNumber":132,"sourceCode":"    //\n    //   semver.satisfies(\"7.0.0-beta.0\", `<7.0.1`) // false - surprising\n    //\n    // and this fails because a prerelease version can only satisfy a range\n    // if it is a prerelease within the same major/minor/patch range.\n    //\n    // Note: If this is found to have issues, please also revisit the logic in\n    // transform-runtime's definitions.js file.\n    if (semver.valid(versionRange)) versionRange = `^${versionRange}`;\n\n    return (\n      !semver.intersects(`<${minVersion}`, versionRange) &&\n      !semver.intersects(`>=9.0.0`, versionRange)\n    );\n  }\n\n  addHelper(name: string): t.Identifier {\n    if (helpers.isInternal(name)) {\n      throw new Error(\"Cannot use internal helper \" + name);\n    }\n    return this._addHelper(name);\n  }\n\n  _addHelper(name: string): t.Identifier {\n    const declar = this.declarations[name];\n    if (declar) return cloneNode(declar);\n\n    const generator = this.get(\"helperGenerator\");\n    if (generator) {\n      const res = generator(name);\n      if (res) return res;\n    }\n\n    // make sure that the helper exists\n    helpers.minVersion(name);\n\n    const uid = (this.declarations[name] =","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/babel/babel/blob/06b6eae39da4ce0689fad64e2c48a6375a464208/packages/babel-core/src/transformation/file/file.ts#L114-L150","documentation":"@babel/helpers marks certain helpers as internal via `helpers.isInternal(name)`. File.addHelper (file.ts:131-133) refuses to inject them because internal helpers are not meant to be emitted into user output.","triggerScenarios":"A plugin calls `path.hub.addHelper(name)` or `file.addHelper(name)` with a helper name that @babel/helpers classifies as internal.","commonSituations":"Writing a custom plugin that tries to reuse a private helper; mistyping a helper name so it resolves to an internal one; using an internal helper that worked in an older helpers version.","solutions":["Check `@babel/helpers` exports and only request public helper names.","Implement the required runtime logic inline in your plugin rather than relying on an internal helper.","Upgrade or downgrade @babel/helpers to match the @babel/core version you depend on."],"exampleFix":"// before\nconst id = path.hub.addHelper('typeof'); // 'typeof' may be internal/renamed\n\n// after: use a public helper or inline it\nconst id = path.hub.addHelper('interopRequireWildcard');\n// or emit your own helper node directly","handlingStrategy":"validation","validationCode":"import { isInternal } from '@babel/helpers';\nfunction safeAddHelper(hub, name) {\n  if (isInternal(name)) throw new Error(`Refusing to request internal helper: ${name}`);\n  return hub.addHelper(name);\n}","typeGuard":"import { isInternal } from '@babel/helpers';\nconst isPublicHelper = (name: string): boolean => !isInternal(name);","tryCatchPattern":"try {\n  path.hub.addHelper(name);\n} catch (err) {\n  if (/Cannot use internal helper/.test(err.message)) {\n    // emit the runtime logic inline instead\n  }\n  throw err;\n}","preventionTips":["Never request helpers by guessed names; consult @babel/helpers' public list.","Lock @babel/helpers and @babel/core to the same version range.","Unit-test custom plugins against the helpers API."],"tags":["babel","helpers","plugins","internal-api"],"analyzedSha":"06b6eae39da4ce0689fad64e2c48a6375a464208","analyzedAt":"2026-08-03T20:13:43.465Z","schemaVersion":2}