# Import Category class in a component

**URL:** https://meta.discourse.org/t/import-category-class-in-a-component/138406
**Category:** Development
**Created:** [January 12, 2020, 11:50pm UTC](https://meta.discourse.org/t/import-category-class-in-a-component/138406 "2020-01-12T23:50:07Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rogerco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rogerco/32/161338_2.png) [@rogerco](https://meta.discourse.org/u/rogerco)
#### Post date: [January 12, 2020, 11:50pm UTC](https://meta.discourse.org/t/import-category-class-in-a-component/138406/1 "2020-01-12T23:50:07Z")

</div>

Developing a component with the code in the Header section using  
`<script type="text/discourse-plugin" version="0.8.26">`  
where I have lines like  
` parentCat = Discourse.Category.findById(get(category, "parent_category_id"));`

I am getting this on the console

> [@](#):
>
> Deprecation notice: Import the Category class instead of using Discourse.Category (deprecated since Discourse 2.4.0) (removal in Discourse 2.5.0)

So what do I actually need to do? If I add an import statement  
`import Category from "discourse/models/category";` at the top of the script it barfs saying  
`SyntaxError: unknown: 'import' and 'export' may only appear at the top level (18:0)`

Please help a novice…

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [January 12, 2020, 11:58pm UTC](https://meta.discourse.org/t/import-category-class-in-a-component/138406/2 "2020-01-12T23:58:52Z")

</div>

> [@rogerco](#):
>
> `import Category from "discourse/models/category";` at the top of the script it barfs saying  
> `SyntaxError: unknown: 'import' and 'export' may only appear at the top level`

You got to use a multi JS file component to get these features see:

> [@Split up theme Javascript into multiple files](https://meta.discourse.org/t/splitting-up-theme-javascript-into-multiple-files/119369):
>
> Complex theme javascript can be split into multiple files, to keep things nicely organised. To use this functionality, simply add files to the /javascripts folder in your theme directory. These files can not be edited from the Discourse UI, so you must use the [Theme CLI](https://meta.discourse.org/t/discourse-theme-cli-console-app-to-help-you-build-themes/82950) or [source the theme from git](https://meta.discourse.org/t/how-to-source-a-theme-from-a-private-git-repository/82584). Javascript files are treated exactly the same as they are in core/plugins, so you should follow the same file/folder structure. Theme files are loaded after core/plugins, so if the filenames match,…

---

<div class="post-metadata">

### Author: ![rogerco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rogerco/32/161338_2.png) [@rogerco](https://meta.discourse.org/u/rogerco)
#### Post date: [January 13, 2020, 10:54am UTC](https://meta.discourse.org/t/import-category-class-in-a-component/138406/3 "2020-01-13T10:54:23Z")

</div>

Thanks @sam, I can just about understand what I need to do.

> [@sam](#):
>
> Currently, these files can not be edited from the Discourse UI

Bit of a shame, but understandable. I guess I can source the theme from my device rather than git.  
Since the warning says it will be removed in 2.5 I guess there will be a way of handling this within the component code well before 2.5 (when is that BTW?)
