# Runtime V3 modules

**URL:** <https://talk.observablehq.com/t/runtime-v3-modules/1767>\
**Category:** Feedback\
**Created:** [March 15, 2019, 2:07am UTC](https://talk.observablehq.com/t/runtime-v3-modules/1767 "2019-03-15T02:07:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bgchen](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bgchen/32/784_2.png) [@bgchen](https://talk.observablehq.com/u/bgchen)\
**Post date:** [March 15, 2019, 2:07am UTC](https://talk.observablehq.com/t/runtime-v3-modules/1767/1 "2019-03-15T02:07:04Z")

</div>

In [this post](https://talk.observablehq.com/t/observable-press-a-publishing-pattern-for-notebooks/1765/4), @mbostock suggests switching over to the runtime V3 modules in our exports.

Here are two issues I noticed with the v3 modules served by Observable; both are apparent if you compare [this v3 module](https://api.observablehq.com/d/647d897e243bbbe2.js?v=3) with [the underlying notebook](https://observablehq.com/d/647d897e243bbbe2)

- First, the URLs to imported non-published notebooks are incorrect:

```js
import define1 from "../3c69b22e8a78157b.js?v=3";

```

should be

```js
import define1 from "../d/3c69b22e8a78157b.js?v=3";

```

or

```js
import define1 from "./3c69b22e8a78157b.js?v=3";

```

- Second, anonymous cells currently don’t appear in the served v3 module. This is fine for some uses, but it means that many cells won’t be displayed if you try to use this to embed the notebook.

Apologies if these are already known issues. Thanks!

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [March 15, 2019, 4:23am UTC](https://talk.observablehq.com/t/runtime-v3-modules/1767/2 "2019-03-15T04:23:42Z")

</div>

Oops, fixed! Imports in v=3 now resolve correctly, and we’ve restored anonymous cells. (We’d like to have a mode that includes only named cells in the future, since you can’t import anonymous cells into notebooks, but that should be an optional optimization rather than the default behavior.)

---

<div class="post-metadata">

**Author:** ![bgchen](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bgchen/32/784_2.png) [@bgchen](https://talk.observablehq.com/u/bgchen)\
**Post date:** [March 16, 2019, 9:05pm UTC](https://talk.observablehq.com/t/runtime-v3-modules/1767/3 "2019-03-16T21:05:06Z")

</div>

Thanks for the quick response!

I’ve noticed an inconsistency between the way notebooks and the v1 runtime files treat multiple imports from the same notebook and the way the v3 runtime files do: Currently, if I have notebook A with multiple import statements referencing notebook B, all of the variables in these imports will come from the same namespace (module?) _unless_ I use `import...with`. The v1 runtime module files served by the API reflect this behavior, but the v3 runtime module files served by the API do not.

I tried to document this behavior in my [“imports tips and tricks” notebook](https://observablehq.com/@bryangingechen/imports-tips-and-tricks#more) a while back, but I’ve also updated [the above scratch notebook](https://observablehq.com/d/647d897e243bbbe2) with a simpler example. There are 3 import statements there:

```auto
import {aa as importeda} from '3c69b22e8a78157b'

```

```auto
import {aa as importeda2} from '3c69b22e8a78157b'

```

```auto
import {aa as importeda3} with {} from '3c69b22e8a78157b'

```

You can see that `importeda === importeda2` is `true` and `importeda === importeda3` is `false`.

Consistent with this, in [the v1 runtime module served by the API](https://api.observablehq.com/d/647d897e243bbbe2.js), `importeda` and `importeda2` are both imported `from: "3c69b22e8a78157b"` (which is module `m1`), whereas `importeda3` is imported `from: "647d897e243bbbe2@789/7"` (which is module `m2`).

However, in the [v3](https://api.observablehq.com/d/647d897e243bbbe2.js?v=3) runtime module, each of these variables is imported from a distinct module: `importeda` comes from `child1`, `importeda2` comes from `child2` and `importeda3` comes from `child3`.

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [March 17, 2019, 12:01am UTC](https://talk.observablehq.com/t/runtime-v3-modules/1767/4 "2019-03-17T00:01:31Z")

</div>

I’m not able to reproduce this bug. If you try it out here, you’ll see that importeda = importeda2 with v3 (the `true` value):

> **[Embedded Notebook](https://observablehq.com/d/34639802388b3418)**
>
> An Observable notebook by Mike Bostock.

Observable’s module resolution bootstraps from ES module resolution. So, because the ES imports resolve to identical values, _runtime_.module returns the same Observable module for each.

> <https://github.com/observablehq/runtime/blob/9019bfef749255b5ae14d8dad8dfc2d91f88bad9/src/runtime.js#L38-L44>

That said, we are generating redundant ES imports, but this should be harmless (other than a few wasted bytes) because they have identical paths.

[https://api.observablehq.com/d/647d897e243bbbe2.js?v=3](https://api.observablehq.com/d/647d897e243bbbe2.js?v=3)

---

<div class="post-metadata">

**Author:** ![bgchen](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bgchen/32/784_2.png) [@bgchen](https://talk.observablehq.com/u/bgchen)\
**Post date:** [March 17, 2019, 1:22am UTC](https://talk.observablehq.com/t/runtime-v3-modules/1767/5 "2019-03-17T01:22:58Z")

</div>

Ah, I should have actually tested this… Sorry for the noise and thanks for the explanation!

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [August 11, 2019, 10:25am UTC](https://talk.observablehq.com/t/runtime-v3-modules/1767/6 "2019-08-11T10:25:37Z")

</div>

Currently v3 sources have a leading comment containing the notebook URL and version. Is this comment part of the API? Can I expect it to exist in every v3 source?

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [August 11, 2019, 2:58pm UTC](https://talk.observablehq.com/t/runtime-v3-modules/1767/7 "2019-08-11T14:58:15Z")

</div>

No, the comment is not part of the API.

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [August 11, 2019, 3:21pm UTC](https://talk.observablehq.com/t/runtime-v3-modules/1767/8 "2019-08-11T15:21:35Z")

</div>

What about the frontmatter lines in v1 / v2 notebooks? Are those guaranteed to stay?

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [August 11, 2019, 8:34pm UTC](https://talk.observablehq.com/t/runtime-v3-modules/1767/9 "2019-08-11T20:34:47Z")

</div>

No, the comments are not part of the API. But as a practical matter, I don’t expect we will be making any substantive changes to them, either.
