Can't import view

Something weird happening with importing modules. Here’s a snippet from my plugin

import PostModel from 'discourse/models/post';
import { withPluginApi } from 'discourse/lib/plugin-api';
import { slot, loadGoogle } from '../lib/gpt';
import TopicView from 'discourse/views/topic';

The first three imports work well, but the last one doesn’t work and i don’t know how to figure out why.

The error: Uncaught ReferenceError: TopicView is not defined

Do you have any idea why importing TopicView doesn’t work?

class TopicView is in ./lib/topic_view.rb , so

maybe try:

import TopicView from 'discourse/lib/topic_view';

No, it’s a javascript part of Discourse, no ruby at all. In repo it has full path:

app/assets/javascripts/discourse/views/topic.js.es6

Shows what I know. :slight_smile:

I admit I’m no expert here.

But it seems odd to me that
/models/post.js.es6 has export default Post;
while
/views/topic.js.es6 has export default TopicView;

My guess is that the line should be
import Topic from 'discourse/views/topic';
in the assumption that topic is exporting TopicView as Topic

No difference.
I found another weirdo, here’s bigger snippet:

import PostModel from 'discourse/models/post';
import { withPluginApi } from 'discourse/lib/plugin-api';
import { slot, loadGoogle } from '../lib/gpt';
import TopicView from 'discourse/views/topic';
// here TopicView is defined
export default {
  name: 'initialize-ad-plugin',
  initialize(container) {
    PostModel.reopen({
    ...
    })
    ...
    // but here TopicView is not defined
    ...
  }
}

TopicView is accessible out of anonymous object, but not inside it. But i don’t understand why there’s no problem with PostModel?

The directory views doesn’t exist in discourse 1.8 so i don’t find the class TopicView…

Does the TopicView class still exist in js ?