# ☠️ Bug: Dynamic imports are broken ☠️

**URL:** <https://talk.observablehq.com/t/bug-dynamic-imports-are-broken/2444>\
**Category:** Feedback\
**Created:** [October 5, 2019, 7:04am UTC](https://talk.observablehq.com/t/bug-dynamic-imports-are-broken/2444 "2019-10-05T07:04:04Z")\
**Posts on this page:** 7\
**Page:** 1

<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:** [October 5, 2019, 7:04am UTC](https://talk.observablehq.com/t/bug-dynamic-imports-are-broken/2444/1 "2019-10-05T07:04:05Z")

</div>

Dynamic imports of the form

```auto
Foo = (await import('https://unpkg.com/foo?module')).default
// or
foo = import("foo")

```

throw the error

```auto
TypeError: i[o] is not a function

```

Examples:

- [Introduction to require / Observable | Observable](https://observablehq.com/@observablehq/introduction-to-require)
- [Hello, delatin / Fil | Observable](https://observablehq.com/@fil/hello-delatin)
- [AgentScript: test es6 module import() and umd require() / Owen Densmore | Observable](https://observablehq.com/@backspaces/agentscript-test-es6-module-import-and-umd-require)

---

<div class="post-metadata">

**Author:** ![mourner](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mourner/32/1298_2.png) [@mourner](https://talk.observablehq.com/u/mourner)\
**Post date:** [October 5, 2019, 7:41am UTC](https://talk.observablehq.com/t/bug-dynamic-imports-are-broken/2444/2 "2019-10-05T07:41:26Z")

</div>

Yep. The workaround I have to use currently is replacing all dynamic imports with `require('https://bundle.run/...')`

---

<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:** [October 5, 2019, 9:32am UTC](https://talk.observablehq.com/t/bug-dynamic-imports-are-broken/2444/3 "2019-10-05T09:32:34Z")

</div>

Sorry, this was my fault! I’ve deployed a fix.

---

<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:** [October 5, 2019, 9:40am UTC](https://talk.observablehq.com/t/bug-dynamic-imports-are-broken/2444/4 "2019-10-05T09:40:10Z")

</div>

Out of curiousity: How did this one sneak past your tests?

---

<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:** [October 5, 2019, 3:17pm UTC](https://talk.observablehq.com/t/bug-dynamic-imports-are-broken/2444/5 "2019-10-05T15:17:49Z")

</div>

The tests passed because our parser was using a newer version of acorn-walk than the server, and a code change relied on a feature that was added in a recent minor of acorn-walk.

---

<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:** [October 5, 2019, 3:32pm UTC](https://talk.observablehq.com/t/bug-dynamic-imports-are-broken/2444/6 "2019-10-05T15:32:45Z")

</div>

Have you considered adding some integration tests? E.g. pick a number of test notebooks and ensure that these render without errors?

---

<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:** [October 5, 2019, 3:43pm UTC](https://talk.observablehq.com/t/bug-dynamic-imports-are-broken/2444/7 "2019-10-05T15:43:20Z")

</div>

Yes, we have integration tests as well, but not ones that covered this specific case.
