# How to import custom components generated by Ionic 3.5 CLI?

**URL:** <https://forum.ionicframework.com/t/how-to-import-custom-components-generated-by-ionic-3-5-cli/99652>\
**Category:** ionic-v3\
**Created:** [July 26, 2017, 2:35pm UTC](https://forum.ionicframework.com/t/how-to-import-custom-components-generated-by-ionic-3-5-cli/99652 "2017-07-26T14:35:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![globophobe](https://avatars.discourse-cdn.com/v4/letter/g/aeb1de/32.png) [@globophobe](https://forum.ionicframework.com/u/globophobe)\
**Post date:** [July 26, 2017, 2:35pm UTC](https://forum.ionicframework.com/t/how-to-import-custom-components-generated-by-ionic-3-5-cli/99652/1 "2017-07-26T14:35:32Z")

</div>

The Ionic 3.5 CLI generates a custom component and puts the following in app.module.ts

```auto
@NgModule(
  declarations: [
    CustomComponent
  ],
)

```

Unfortunately, I got an error that, ‘custom-component’ is not a known element.

For the moment, I removed CustomComponent from declarations in app.module.ts and added the following to imports in each module that needs the component. This seems OK.

For example, in page.module.ts

```auto
@NgModule(
  imports: [
    CustomComponentModule
  ]
)

```

How to import custom components generated by Ionic 3.5 CLI?

I would appreciate your advice and suggestions.

Thanx.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [July 26, 2017, 7:22pm UTC](https://forum.ionicframework.com/t/how-to-import-custom-components-generated-by-ionic-3-5-cli/99652/2 "2017-07-26T19:22:34Z")

</div>

> [@globophobe](#):
>
> I removed CustomComponent from declarations in app.module.ts and added the following to imports in each module that needs the component. This seems OK.

Beware that your app binary is going to contain a separate copy of all of `CustomComponent`’s code for each page that imports it thusly.

---

<div class="post-metadata">

**Author:** ![globophobe](https://avatars.discourse-cdn.com/v4/letter/g/aeb1de/32.png) [@globophobe](https://forum.ionicframework.com/u/globophobe)\
**Post date:** [July 27, 2017, 12:12am UTC](https://forum.ionicframework.com/t/how-to-import-custom-components-generated-by-ionic-3-5-cli/99652/3 "2017-07-27T00:12:46Z")

</div>

> [@rapropos](#):
>
> Beware that your app binary is going to contain a separate copy of all of CustomComponent’s code for each page that imports it thusly.

Thank you. I knew that from one of your other forum posts. Anyway, I think I make a mistake in app.module.ts

Before:

```auto
@NgModule(
  declarations: [
    CustomComponent
  ],
  imports: [
    PageModule
  ],
  entryComponents: []
)

```

After:

```auto
@NgModule(
  declarations: [
    Page
    CustomComponent
  ],
  imports: [],
  entryComponents: [
    Page
  ]
)

```

It’s OK now. Thanks again.

---

<div class="post-metadata">

**Author:** ![globophobe](https://avatars.discourse-cdn.com/v4/letter/g/aeb1de/32.png) [@globophobe](https://forum.ionicframework.com/u/globophobe)\
**Post date:** [July 27, 2017, 2:45pm UTC](https://forum.ionicframework.com/t/how-to-import-custom-components-generated-by-ionic-3-5-cli/99652/4 "2017-07-27T14:45:17Z")

</div>

OK. It was fine with “ionic serve”, but now that I am ready for “npm run build --prod” I get:

```auto
[23:40:18] ionic-app-script task: "build" 
[23:40:18] Error: Type CustomComponent in 
            /src/components/custom/custom.ts is part of the declarations 
            of 2 modules: ...

```

As a result, I remembered why I had initially altered my imports.

Unfortunately, back to the original question.

How to import custom components generated by Ionic 3.5 CLI?

---

<div class="post-metadata">

**Author:** ![meysammahfouzi](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/meysammahfouzi/32/113600_2.png) [@meysammahfouzi](https://forum.ionicframework.com/u/meysammahfouzi)\
**Post date:** [October 6, 2017, 6:29pm UTC](https://forum.ionicframework.com/t/how-to-import-custom-components-generated-by-ionic-3-5-cli/99652/5 "2017-10-06T18:29:35Z")

</div>

I’ve got the same problem. Please somebody clarify.

---

<div class="post-metadata">

**Author:** ![barakbd](https://avatars.discourse-cdn.com/v4/letter/b/f475e1/32.png) [@barakbd](https://forum.ionicframework.com/u/barakbd)\
**Post date:** [October 10, 2017, 8:30pm UTC](https://forum.ionicframework.com/t/how-to-import-custom-components-generated-by-ionic-3-5-cli/99652/6 "2017-10-10T20:30:38Z")

</div>

Same problem here. Are we supposed to import the component into each page individually? That doesn’t seem very efficient.  
Also, if the intended behavior is to import each component.module at the page level, then why does the CLI import it to app.module by default? That is very confusing.  
You could still achieve lazy loading by importing a reference to location of the piece of code for the specific component in app.module, and not actually loading it in memory.
