Repository: angular/angular
File: packages/core/src/render3/def_getters.ts (TypeScript)

Code before:
  return type[NG_COMP_DEF] || null;
}

export function getDirectiveDefOrThrow<T>(type: any): DirectiveDef<T> | never {
  const def = getDirectiveDef<T>(type);
  if (!def) {
    throw new RuntimeError(
      RuntimeErrorCode.MISSING_DIRECTIVE_DEFINITION,
      (typeof ngDevMode === 'undefined' || ngDevMode) &&
        `Type ${stringify(type)} does not have 'ɵdir' property.`,
    );
  }
  return def;
}

export function getDirectiveDef<T>(type: any): DirectiveDef<T> | null {
  if (typeof ngDevMode === 'undefined' || ngDevMode) {
    assertTypeDefined(type, '@Directive');
  }
  return type[NG_DIR_DEF] || null;
}

export function getPipeDef<T>(type: any): PipeDef<T> | null {
  if (typeof ngDevMode === 'undefined' || ngDevMode) {
    assertTypeDefined(type, '@Pipe');
  }
  return type[NG_PIPE_DEF] || null;
}

function assertTypeDefined(type: any, symbolType: string): void {
  if (type == null) {
    throw new RuntimeError(
      RuntimeErrorCode.DEF_TYPE_UNDEFINED,
      `Cannot read ${symbolType} metadata from "${type}". This can indicate a runtime ` +
        `circular dependency in your app that needs to be resolved.`,
    );
  }
}

/**
 * Checks whether a given Component, Directive or Pipe is marked as standalone.
 * This will return false if passed anything other than a Component, Directive, or Pipe class
 * See [this guide](guide/components/importing) for additional information:
 *
 * @param type A reference to a Component, Directive or Pipe.
 * @publicApi
 */
export function isStandalone(type: Type<unknown>): boolean {
  const def = getComponentDef(type) || getDirectiveDef(type) || getPipeDef(type);
  return def !== null && def.standalone;
}

Review comment (suggestion):
I'm wondering if we should also assert in prod mode too and only strip the error message in prod mode. 

What I've often seen reported is this issue happening only in prodmode because of the different bundler at play (vite in dev vs esbuild in prod).

Code after:
  const def = getDirectiveDef<T>(type);
  if (!def) {
    throw new RuntimeError(
      RuntimeErrorCode.MISSING_DIRECTIVE_DEFINITION,
      (typeof ngDevMode === 'undefined' || ngDevMode) &&
        `Type ${stringify(type)} does not have 'ɵdir' property.`,
    );
  }
  return def;
}

export function getDirectiveDef<T>(type: any): DirectiveDef<T> | null {
  assertTypeDefined(type, '@Directive');
  return type[NG_DIR_DEF] || null;
}

export function getPipeDef<T>(type: any): PipeDef<T> | null {
  assertTypeDefined(type, '@Pipe');
  return type[NG_PIPE_DEF] || null;
}

function assertTypeDefined(type: any, symbolType: string): void {
  if (type == null) {
    throw new RuntimeError(
      RuntimeErrorCode.DEF_TYPE_UNDEFINED,
      (typeof ngDevMode === 'undefined' || ngDevMode) &&
        `Cannot read ${symbolType} metadata. This can indicate a runtime ` +
          `circular dependency in your app that needs to be resolved.`,
    );
  }
}

/**
 * Checks whether a given Component, Directive or Pipe is marked as standalone.
 * This will return false if passed anything other than a Component, Directive, or Pipe class
 * See [this guide](guide/components/importing) for additional information:
 *
 * @param type A reference to a Component, Directive or Pipe.
 * @publicApi
 */
export function isStandalone(type: Type<unknown>): boolean {
  const def = getComponentDef(type) || getDirectiveDef(type) || getPipeDef(type);
  return def !== null && def.standalone;
}