# Can't import view

**URL:** https://meta.discourse.org/t/cant-import-view/50402
**Category:** Development
**Created:** [September 20, 2016, 6:27pm UTC](https://meta.discourse.org/t/cant-import-view/50402 "2016-09-20T18:27:19Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![sevenmaxis](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@sevenmaxis](https://meta.discourse.org/u/sevenmaxis)
#### Post date: [September 20, 2016, 6:27pm UTC](https://meta.discourse.org/t/cant-import-view/50402/1 "2016-09-20T18:27:19Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 20, 2016, 7:39pm UTC](https://meta.discourse.org/t/cant-import-view/50402/2 "2016-09-20T19:39:33Z")

</div>

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

maybe try:

```
import TopicView from 'discourse/lib/topic_view';

```

---

<div class="post-metadata">

### Author: ![sevenmaxis](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@sevenmaxis](https://meta.discourse.org/u/sevenmaxis)
#### Post date: [September 20, 2016, 7:45pm UTC](https://meta.discourse.org/t/cant-import-view/50402/3 "2016-09-20T19:45:45Z")

</div>

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`

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 20, 2016, 7:46pm UTC](https://meta.discourse.org/t/cant-import-view/50402/4 "2016-09-20T19:46:16Z")

</div>

Shows what I know. 🙂

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [September 20, 2016, 8:17pm UTC](https://meta.discourse.org/t/cant-import-view/50402/5 "2016-09-20T20:17:13Z")

</div>

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

---

<div class="post-metadata">

### Author: ![sevenmaxis](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@sevenmaxis](https://meta.discourse.org/u/sevenmaxis)
#### Post date: [September 20, 2016, 8:58pm UTC](https://meta.discourse.org/t/cant-import-view/50402/6 "2016-09-20T20:58:53Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Clement\_Decou](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/clement_decou/32/67776_2.png) [@Clement\_Decou](https://meta.discourse.org/u/Clement_Decou)
#### Post date: [February 16, 2017, 10:52am UTC](https://meta.discourse.org/t/cant-import-view/50402/7 "2017-02-16T10:52:39Z")

</div>

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 ?
