{"record":{"id":"16d2c71b7fcf3519","repo":"ionic-team/ionic-framework","slug":"invalid-views-to-insert","errorCode":null,"errorMessage":"invalid views to insert","messagePattern":"invalid views to insert","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"core/src/components/nav/nav.tsx","lineNumber":731,"sourceCode":"\n    if (ti.insertViews) {\n      // allow -1 to be passed in to auto push it on the end\n      // and clean up the index if it's larger then the size of the stack\n      if (ti.insertStart! < 0 || ti.insertStart! > viewsLength) {\n        ti.insertStart = viewsLength;\n      }\n      ti.enteringRequiresTransition = ti.insertStart === viewsLength;\n    }\n\n    const insertViews = ti.insertViews;\n    if (!insertViews) {\n      return;\n    }\n    assert(insertViews.length > 0, 'length can not be zero');\n    const viewControllers = convertToViews(insertViews);\n\n    if (viewControllers.length === 0) {\n      throw new Error('invalid views to insert');\n    }\n\n    // Check all the inserted view are correct\n    for (const view of viewControllers) {\n      view.delegate = ti.opts.delegate;\n      const nav = view.nav;\n      if (nav && nav !== this) {\n        throw new Error('inserted view was already inserted');\n      }\n      if (view.state === VIEW_STATE_DESTROYED) {\n        throw new Error('inserted view was already destroyed');\n      }\n    }\n    ti.insertViews = viewControllers;\n  }\n\n  /**\n   * Returns the view that will be entered considering the transition instructions.","sourceCodeStart":713,"sourceCodeEnd":749,"githubUrl":"https://github.com/ionic-team/ionic-framework/blob/625f9c38ad8c5db8a6c12df5c1622a36da90f9e3/core/src/components/nav/nav.tsx#L713-L749","documentation":"Thrown in IonNav.prepareTI() when `convertToViews(insertViews)` returns an empty array. convertToViews builds ViewController instances from the supplied components; an empty result means none of the supplied items could be turned into a valid view (e.g. they were undefined/null/not a component). This guards the nav against inserting nothing on a push/insert/setRoot/setPages call.","triggerScenarios":"Calling `nav.push(component)`, `nav.insert(...)`, `nav.setRoot(component)`, or `nav.setPages([...])` with a component that is `undefined`, `null`, not a valid component reference, or an array whose entries all fail conversion.","commonSituations":"Passing a lazily-imported component that resolved to undefined (broken dynamic import); typo in a component reference; passing a string instead of a component class/element; tree-shaking stripping the component; circular import returning undefined at evaluation time.","solutions":["Verify the component reference is defined at the call site (`console.assert(MyComponent)`).","For dynamic imports, `await` them and confirm the resolved value before passing: `const C = (await import('./c')).default; if (C) nav.setRoot(C);`.","If using setPages/insertPages, ensure every array entry is a valid component or `{ component, componentProps }` object.","Check for circular imports that evaluate the component before it is assigned."],"exampleFix":"// before\nawait nav.push(undefined);\n// after\nimport { HomePage } from './home.page';\nawait nav.push(HomePage);","handlingStrategy":"type-guard","validationCode":"// Ensure the component is a valid, defined component before pushing\nfunction isValidComponent(c: any): boolean {\n  return c != null && (typeof c === 'function' || typeof c === 'object');\n}\nif (!isValidComponent(component)) {\n  throw new Error(`Invalid component passed to nav: ${component}`);\n}\nawait nav.push(component);","typeGuard":"function isNavComponent(c: any): boolean {\n  return c != null && (typeof c === 'function' || (typeof c === 'object' && typeof c.prototype !== 'undefined'));\n}","tryCatchPattern":"try {\n  await nav.push(component);\n} catch (e) {\n  if ((e as Error).message === 'invalid views to insert') {\n    console.error('Component could not be converted to a view:', component);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Confirm dynamic imports are awaited and resolve to a defined component.","Avoid passing strings or undefined to push/setRoot/insert/setPages.","Watch for circular imports that yield undefined at evaluation time."],"tags":["core","ion-nav","navigation","validation"],"backgroundTag":null,"analyzedSha":"625f9c38ad8c5db8a6c12df5c1622a36da90f9e3","analyzedAt":"2026-08-12T16:00:25.413Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}