# Improve the output for an import statement

**URL:** <https://talk.observablehq.com/t/improve-the-output-for-an-import-statement/1912>\
**Category:** Feedback\
**Created:** [April 24, 2019, 10:34pm UTC](https://talk.observablehq.com/t/improve-the-output-for-an-import-statement/1912 "2019-04-24T22:34:06Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![j-f1](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/j-f1/32/368_2.png) [@j-f1](https://talk.observablehq.com/u/j-f1)\
**Post date:** [April 24, 2019, 10:34pm UTC](https://talk.observablehq.com/t/improve-the-output-for-an-import-statement/1912/1 "2019-04-24T22:34:06Z")

</div>

Currently, this is the output shown above a cell containing an `import` statement:

> `import @j-f1/fetch-from-wikipedia`

This does provide some utility over just showing the code view, since the name links to the source notebook, but unlike the other visualizations, it doesn’t list the name/names imported from the statement. Would it be possible to display the names, perhaps using the same syntax as the import statement uses?

> `import { fetchPage } from @j-f1/fetch-from-wikipedia`

alternative proposal:

> `import { fetchPage } from @j-f1/fetch-from-wikipedia`

---

<div class="post-metadata">

**Author:** ![jashkenas](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jashkenas/32/1778_2.png) [@jashkenas](https://talk.observablehq.com/u/jashkenas)\
**Post date:** [April 24, 2019, 10:41pm UTC](https://talk.observablehq.com/t/improve-the-output-for-an-import-statement/1912/2 "2019-04-24T22:41:59Z")

</div>

Great idea. And since cell names are linkable with `#cellName` notation — it would be even nicer if:

> `import { fetchPage } from @j-f1/fetch-from-wikipedia`

… linked directly to the definition of the cell that you have imported.

---

<div class="post-metadata">

**Author:** ![j-f1](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/j-f1/32/368_2.png) [@j-f1](https://talk.observablehq.com/u/j-f1)\
**Post date:** [April 24, 2019, 10:44pm UTC](https://talk.observablehq.com/t/improve-the-output-for-an-import-statement/1912/3 "2019-04-24T22:44:43Z")

</div>

Yes! 💖

Seeing that version, since all the “important” bits (i.e. the ones that change between different import statements) are highlighted by virtue of being a link, the bold is less necessary:

> `import { fetchPage } from @j-f1/fetch-from-wikipedia`

---

<div class="post-metadata">

**Author:** ![jrus](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jrus/32/586_2.png) [@jrus](https://talk.observablehq.com/u/jrus)\
**Post date:** [April 25, 2019, 4:54pm UTC](https://talk.observablehq.com/t/improve-the-output-for-an-import-statement/1912/4 "2019-04-25T16:54:38Z")

</div>

Yes, I currently always leave code blocks with imports pinned open, because otherwise it is impossible to search on the page for variable names defined therein. I have several times wished the names were written in the output, but never bothered filing a ticket here.

In the case of `import {chart as treemap} from "@d3/treemap"` (to take an example from [introduction to imports](https://observablehq.com/@observablehq/introduction-to-imports)), the name `treemap` should get into the rendered cell output. Whether the name `chart` does is less important.

---

<div class="post-metadata">

**Author:** ![jashkenas](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jashkenas/32/1778_2.png) [@jashkenas](https://talk.observablehq.com/u/jashkenas)\
**Post date:** [April 25, 2019, 6:01pm UTC](https://talk.observablehq.com/t/improve-the-output-for-an-import-statement/1912/5 "2019-04-25T18:01:58Z")

</div>

Thanks for the nudge on this, folks.

We’ve just deployed an update that implements this, and links directly to the imported cells.

As a bonus, you can see if you happened to fat-finger an import, and tried to import a cell that doesn’t exist:

![image](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/8/818512df7c0a939f550b266e733159b238e866b0.png)

Enjoy, and let me know if you notice any room for further improvement (we have some further ideas in this direction for later…)

---

<div class="post-metadata">

**Author:** ![jrus](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jrus/32/586_2.png) [@jrus](https://talk.observablehq.com/u/jrus)\
**Post date:** [April 26, 2019, 3:05am UTC](https://talk.observablehq.com/t/improve-the-output-for-an-import-statement/1912/6 "2019-04-26T03:05:52Z")

</div>

Perhaps make non-existent ones red instead of gray. Or maybe that’s too distracting.

---

<div class="post-metadata">

**Author:** ![j-f1](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/j-f1/32/368_2.png) [@j-f1](https://talk.observablehq.com/u/j-f1)\
**Post date:** [April 26, 2019, 10:55am UTC](https://talk.observablehq.com/t/improve-the-output-for-an-import-statement/1912/7 "2019-04-26T10:55:00Z")

</div>

Shouldn’t it throw an error if the import doesn’t exist?

---

<div class="post-metadata">

**Author:** ![jashkenas](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jashkenas/32/1778_2.png) [@jashkenas](https://talk.observablehq.com/u/jashkenas)\
**Post date:** [April 26, 2019, 6:55pm UTC](https://talk.observablehq.com/t/improve-the-output-for-an-import-statement/1912/8 "2019-04-26T18:55:56Z")

</div>

> [@j-f1](#):
>
> Shouldn’t it throw an error if the import doesn’t exist?

As things stand currently, the error is thrown as soon as you try to reference the nonexistent import.

---

<div class="post-metadata">

**Author:** ![jrus](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jrus/32/586_2.png) [@jrus](https://talk.observablehq.com/u/jrus)\
**Post date:** [May 8, 2019, 7:47pm UTC](https://talk.observablehq.com/t/improve-the-output-for-an-import-statement/1912/9 "2019-05-08T19:47:16Z")

</div>

This feature has been very helpful, a big improvement over the previous behavior. Thanks again Jeremy! (And Jed.)

---

<div class="post-metadata">

**Author:** ![jrus](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jrus/32/586_2.png) [@jrus](https://talk.observablehq.com/u/jrus)\
**Post date:** [May 8, 2019, 7:52pm UTC](https://talk.observablehq.com/t/improve-the-output-for-an-import-statement/1912/10 "2019-05-08T19:52:47Z")

</div>

Oh one possible modification: if the import is to a version-pinned notebook, it might be nice if the links go to the relevant version.

---

<div class="post-metadata">

**Author:** ![bchoatejr](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bchoatejr/32/1617_2.png) [@bchoatejr](https://talk.observablehq.com/u/bchoatejr)\
**Post date:** [June 14, 2019, 5:11pm UTC](https://talk.observablehq.com/t/improve-the-output-for-an-import-statement/1912/11 "2019-06-14T17:11:17Z")

</div>

When the import cell is unpinned, would it be possible to show the “with” options and use the same link behavior? I was searching for an import in my notebooks using the “with” option and couldn’t find them at first. I didn’t realize that when the import cell is unpinned, the with portion is not shown. Thanks again for all the cool features.
