Can't import view

AI-generated summary

The discussion is about an issue with importing a TopicView in a Discourse plugin. sevenmaxis is trying to import TopicView from discourse/views/topic but is getting an Uncaught ReferenceError. pfaffman suggested a possible solution, but it was not correct as TopicView is a JavaScript component. Mittineague suggested a possible issue with the export name, but sevenmaxis found that it didn’t make a difference. The issue seems to be scope-related, as TopicView is accessible outside of an anonymous object but not inside it. However, Clement_Decou pointed out that the views directory does not exist in Discourse 1.8, which may indicate that the TopicView class has been removed or relocated.

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 ?