Can you get it down to a minimal reproduction you can share here? Without more details, it’s hard to say! Happy to help if I can, but if you can make a minimal component and template combo that will make troubleshooting more possible.
This is not supported with Glimmer components; it’s one of the API differences between them and Ember components. You should prefer to just use the normal conventional locations of templates and backing classes (whether in templates directory or colocated), and that’ll work. If you’re on latest, using colocation is recommended:
app/
components/
my-component.js
my-component.hbs
using private API
THIS IS VERY EXTREMELY NOT RECOMMENDED!!!
If you absolutely need to do it with imports for some reason, you can do it like this:
import Component from '@glimmer/component';
import { setComponentTemplate } from '@ember/-internals/glimmer';
import template from './template';
export default class HelloWorld extends Component {
constructor() {
super(...arguments);
console.log('Hello from constructor');
}
}
setComponentTemplate(template, HelloWorld);
Once again: this is private API, and you basically should never need it. Just use colocated templates instead (it does this for you, and is guaranteed to keep working!).
It’s possible that this API or one like it will be public in the future, but no guarantees!
Thanks for the insight. I’ve tried to use normal (the old) convention of placing component and template and that didn’t work either, only colocation works.
Does that mean that pods structure is now deprecated?
Sadly not, we’re still using the old components ATM.
We plan to migrate away from engines (the benefits are negligible compared to the issues we have with them) and then we hope to use the new stuff in Ember.
@G_M what issue specifically are you having? Trying to use pod format with glimmer components in an addon? Anything stopping you from migrating to co-location?
We’re doing the same at my company. The nice thing is they don’t conflict so you don’t have to do it all at once, and the directory version of co-location is almost the exact same as pods. I personally prefer not using directories with co-location (e.g. my-component/component.js becomes my-component.js) but if you’re looking to stay closer to pods format you can always just rename to “index” and keep the directories e.g. my-component/component.js becomes my-component/index.js