{"record":{"id":"928085edcab0fc36","repo":"apache/cordova-android","slug":"failed-to-instantiate-projectbuilder-builder-er","errorCode":null,"errorMessage":"Failed to instantiate ProjectBuilder builder: ${err}","messagePattern":"Failed to instantiate ProjectBuilder builder: (.+?)","errorType":"exception","errorClass":"CordovaError","httpStatus":null,"severity":"error","filePath":"lib/builders/builders.js","lineNumber":32,"sourceCode":"    \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n    KIND, either express or implied.  See the License for the\n    specific language governing permissions and limitations\n    under the License.\n*/\n\nconst CordovaError = require('cordova-common').CordovaError;\n\n/**\n * Helper method that instantiates and returns a builder for specified build type.\n *\n * @return {Builder} A builder instance for specified build type.\n */\nmodule.exports.getBuilder = function (projectPath) {\n    try {\n        const Builder = require('./ProjectBuilder');\n        return new Builder(projectPath);\n    } catch (err) {\n        throw new CordovaError('Failed to instantiate ProjectBuilder builder: ' + err);\n    }\n};\n","sourceCodeStart":14,"sourceCodeEnd":35,"githubUrl":"https://github.com/apache/cordova-android/blob/7c1e190064e349ffa4bbc6ac37b77cd773e4dbd3/lib/builders/builders.js#L14-L35","documentation":"builders.getBuilder(projectPath) require()s ./ProjectBuilder and constructs it inside a try/catch; any throw during module load (missing transitive dependency, syntax error, EPERM reading a file) or from the constructor is stringified into a CordovaError. The original stack is flattened, so the message's embedded 'Error: ...' text is the real cause. This error almost always indicates a broken cordova-android installation rather than a project problem.","triggerScenarios":"Any build/run (`cordova build android`, Api.build) on an install where require('./ProjectBuilder') or `new Builder(projectPath)` throws - corrupted node_modules after an interrupted npm install, version-skew between cordova-android and cordova-common, or file munging by antivirus/lockers on Windows.","commonSituations":"Interrupted or partial npm install; mixing globally installed cordova with a locally pinned cordova-android; upgrading cordova without upgrading the platform; antivirus quarantining files.","solutions":["Read the embedded inner error text after 'builder: ' - it names the actual failure (e.g. Cannot find module 'X').","Reinstall dependencies cleanly: rm -rf node_modules package-lock.json && npm install (or npm ci).","Regenerate the platform: `cordova platform rm android && cordova platform add android`.","Check version compatibility between the cordova CLI and cordova-android platform (package.json / cordova -v)."],"exampleFix":"# before\n$ cordova build android\nFailed to instantiate ProjectBuilder builder: Error: Cannot find module 'lodash'\n\n# after\n$ rm -rf node_modules package-lock.json && npm install\n$ cordova platform rm android && cordova platform add android\n$ cordova build android","handlingStrategy":"try-catch","validationCode":"// Preflight: load the builder module the same way getBuilder does\ntry {\n  require.resolve('cordova-android/lib/builders/ProjectBuilder');\n} catch (e) {\n  throw new Error('cordova-android install is broken - run npm ci / reinstall the platform: ' + e.message);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const builder = builders.getBuilder(projectPath);\n} catch (e) {\n  if (/Failed to instantiate ProjectBuilder/.test(e.message)) {\n    const inner = /Error: (.*)/.exec(e.message)?.[1] || e.message;\n    throw new Error(`Broken cordova-android install (${inner}) - rm -rf node_modules && npm ci, then re-add the platform`);\n  }\n  throw e;\n}","preventionTips":["Use npm ci (not ad-hoc npm install) in CI for reproducible, complete installs.","Pin exact cordova and cordova-android versions in package.json to avoid CLI/platform skew.","Never interrupt an npm install or platform add mid-run; if it breaks, redo it cleanly."],"tags":["node-modules","installation","builder","require","corrupt-install"],"backgroundTag":"class-instantiation-failed","analyzedSha":"7c1e190064e349ffa4bbc6ac37b77cd773e4dbd3","analyzedAt":"2026-08-22T04:57:58.868Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}