{"record":{"id":"8da0025e57618245","repo":"angular/angular-cli","slug":"cannot-find-main-entrypoint","errorCode":null,"errorMessage":"Cannot find 'main' entrypoint.","messagePattern":"Cannot find 'main' entrypoint\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/build_angular/src/builders/karma/find-tests-plugin.ts","lineNumber":50,"sourceCode":"    const {\n      include = ['**/*.spec.ts'],\n      exclude = [],\n      projectSourceRoot,\n      workspaceRoot,\n    } = this.options;\n    const webpackOptions = compiler.options;\n    const entry =\n      typeof webpackOptions.entry === 'function' ? webpackOptions.entry() : webpackOptions.entry;\n\n    let originalImport: string[] | undefined;\n\n    // Add tests files are part of the entry-point.\n    webpackOptions.entry = async () => {\n      const specFiles = await findTests(include, exclude, workspaceRoot, projectSourceRoot);\n      const entrypoints = await entry;\n      const entrypoint = entrypoints['main'];\n      if (!entrypoint.import) {\n        throw new Error(`Cannot find 'main' entrypoint.`);\n      }\n\n      if (specFiles.length) {\n        originalImport ??= entrypoint.import;\n        entrypoint.import = [...originalImport, ...specFiles];\n      } else {\n        assert(this.compilation, 'Compilation cannot be undefined.');\n        this.compilation\n          .getLogger(pluginName)\n          .error(`Specified patterns: \"${include.join(', ')}\" did not match any spec files.`);\n      }\n\n      return entrypoints;\n    };\n\n    compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {\n      this.compilation = compilation;\n      compilation.contextDependencies.add(projectSourceRoot);","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/build_angular/src/builders/karma/find-tests-plugin.ts#L32-L68","documentation":"find-tests-plugin is a webpack plugin for the karma builder that augments the 'main' entrypoint with discovered spec files. It expects the webpack configuration's entry factory to return an entrypoints object containing a 'main' key with an `import` array. If the 'main' entrypoint is missing or lacks an `import` property, it throws, because it cannot inject test files.","triggerScenarios":"The karma builder's entry factory returns entrypoints without a 'main' key (e.g. options.main was not set, or entry is a different shape); the entrypoint object lacks an `import` array (incompatible webpack entry format or another plugin rewrote it).","commonSituations":"Configuring the karma builder without a `main` option and without built-in defaults; another webpack plugin replacing entry with a single string/object form; upgrading the karma builder against an older webpack entry configuration.","solutions":["Ensure the karma builder options provide a valid `main` entrypoint file (e.g. src/test.ts) or rely on a builder version that supplies defaults.","Check for other plugins mutating `entry` and remove/reorder them so find-tests-plugin sees an esbuild-style entry object with `import`.","Verify you are not overriding entry to a string/array form in a custom webpack merge; keep the object-of-entrypoints shape.","Update @angular-devkit/build-angular to a version where the karma builder always produces the expected entry structure."],"exampleFix":"// before (builder options)\n{ \"builder\": \"@angular-devkit/build-angular:karma\", \"options\": {} }\n// after\n{ \"builder\": \"@angular-devkit/build-angular:karma\", \"options\": { \"main\": \"src/test.ts\" } }","handlingStrategy":"validation","validationCode":"const entrypoints = await entry();\nif (!entrypoints['main']?.import) {\n  throw new Error('karma entry must contain a main entrypoint with an import array');\n}","typeGuard":"function hasMainImport(e: unknown): e is { main: { import: string[] } } {\n  return !!e && typeof e === 'object' && 'main' in e &&\n    !!((e as any).main) && Array.isArray((e as any).main.import);\n}","tryCatchPattern":"try {\n  applyFindTestsPlugin(compiler, options);\n} catch (e) {\n  if (e.message.includes(\"Cannot find 'main' entrypoint\")) {\n    console.error('Set the karma builder \"main\" option (e.g. src/test.ts).');\n  } else throw e;\n}","preventionTips":["Always set the `main` option in karma builder options.","Avoid webpack merges that convert entry to string/array form.","Order plugins so find-tests-plugin sees the final entry shape.","Keep @angular-devkit/build-angular up to date."],"tags":["karma","webpack","angular","config"],"backgroundTag":"missing-entrypoint","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}