Import Category class in a component

AI-generated summary

A deprecation notice is displayed when using Discourse.Category.findById in a component, recommending to import the Category class instead. However, adding an import statement import Category from "discourse/models/category"; at the top of the script results in a syntax error, as import statements can only be used at the top level. sam suggests using a multi JS file component, as described in the Discourse meta thread, to resolve the issue. rogerco acknowledges the workaround, but notes that this requires editing files outside of the Discourse UI.

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

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…

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

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

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?)