MCPcopy Create free account
hub / github.com/angular/angular / verifyStandaloneImport

Function verifyStandaloneImport

packages/core/src/render3/jit/util.ts:49–98  ·  view source on GitHub ↗
(depType: Type<unknown>, importingType: Type<unknown>)

Source from the content-addressed store, hash-verified

47}
48
49export function verifyStandaloneImport(depType: Type<unknown>, importingType: Type<unknown>) {
50 if (isForwardRef(depType)) {
51 depType = resolveForwardRef(depType);
52 if (!depType) {
53 throw new Error(
54 `Expected forwardRef function, imported from "${stringifyForError(
55 importingType,
56 )}", to return a standalone entity or NgModule but got "${
57 stringifyForError(depType) || depType
58 }".`,
59 );
60 }
61 }
62
63 if (getNgModuleDef(depType) == null) {
64 const def = getComponentDef(depType) || getDirectiveDef(depType) || getPipeDef(depType);
65 if (def != null) {
66 // if a component, directive or pipe is imported make sure that it is standalone
67 if (!def.standalone) {
68 const type = getDependencyTypeForError(depType);
69 throw new Error(
70 `The "${stringifyForError(depType)}" ${type}, imported from "${stringifyForError(
71 importingType,
72 )}", is not standalone. Does the ${type} have the standalone: false flag?`,
73 );
74 }
75 } else {
76 // it can be either a module with provider or an unknown (not annotated) type
77 if (isModuleWithProviders(depType)) {
78 throw new Error(
79 `A module with providers was imported from "${stringifyForError(
80 importingType,
81 )}". Modules with providers are not supported in standalone components imports.`,
82 );
83 } else if (isForeignComponent(depType)) {
84 throw new Error(
85 `A foreign component, imported from "${stringifyForError(
86 importingType,
87 )}", cannot be imported using 'imports'. Foreign components are only supported in AOT mode and must be registered in 'foreignImports'.`,
88 );
89 } else {
90 throw new Error(
91 `The "${stringifyForError(depType)}" type, imported from "${stringifyForError(
92 importingType,
93 )}", must be a standalone component / directive / pipe or an NgModule. Did you forget to add the required @Component / @Directive / @Pipe or @NgModule annotation?`,
94 );
95 }
96 }
97 }
98}

Callers 3

directiveDefsFunction · 0.90
pipeDefsFunction · 0.90

Calls 10

isForwardRefFunction · 0.90
resolveForwardRefFunction · 0.90
stringifyForErrorFunction · 0.90
getNgModuleDefFunction · 0.90
getComponentDefFunction · 0.90
getDirectiveDefFunction · 0.90
getPipeDefFunction · 0.90
isForeignComponentFunction · 0.85
isModuleWithProvidersFunction · 0.70

Tested by

no test coverage detected