# Quarto : module require

**URL:** <https://talk.observablehq.com/t/quarto-module-require/6573>\
**Category:** Help\
**Created:** [May 18, 2022, 1:13pm UTC](https://talk.observablehq.com/t/quarto-module-require/6573 "2022-05-18T13:13:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![neocarto](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/neocarto/32/6554_2.png) [@neocarto](https://talk.observablehq.com/u/neocarto)\
**Post date:** [May 18, 2022, 1:13pm UTC](https://talk.observablehq.com/t/quarto-module-require/6573/1 "2022-05-18T13:13:40Z")

</div>

As you probably know, it is now possible to run Observable code in Quarto [(see)](https://quarto.org/) and combine it with other languages. This is really great !!!  
So I did a few tests [(see)](https://github.com/neocarto/Quarto) and it works perfectly well. However, I can’t import the bertinjs library with the require(“bertin@0.9.15”) instruction, which works perfectly within Observable. The message is OJS Error RequireError$1: invalid module. Actually, only the import(‘[https://cdn.skypack.dev/bertin@0.9.15](https://cdn.skypack.dev/bertin@0.9.15)’) instruction works. I created other modules in the same way, but they work. In short, being a beginner in javascript, I have no idea where the problem can come from. Any help is welcome. My github repo is here : [GitHub - neocarto/bertin: A package to draw maps in javascript](https://github.com/neocarto/bertin).  
See also [javascript - Error Quarto require invalid module (bertin.js) - Stack Overflow](https://stackoverflow.com/questions/72300480/error-quarto-require-invalid-module-bertin-js)

---

<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:** [May 19, 2022, 1:02pm UTC](https://talk.observablehq.com/t/quarto-module-require/6573/2 "2022-05-19T13:02:13Z")

</div>

There are two instances of `d3-require`. When both try to require a package simultaneously, only the last will succeed. You can find more information and a workaround here:

> **[Handling Multiple Require Instances](https://observablehq.com/@mootari/require-conflict)**
>
> When multiple \`d3-require\` instances load scripts simultaneously, only the last call will succeed. This notebook implements a workaround to handle multiple \`define\` callbacks. Import: Then make the following call once before calling \`.require()\` on a...

I wrote that notebook because a similar problem occurred in [Range Slider / Fabian Iwand / Observable](https://observablehq.com/@mootari/range-slider) where [Inputs / Jeremy Ashkenas / Observable](https://observablehq.com/@jashkenas/inputs) gets imported lazily via a separate Runtime instance.

The name `requireCompat` will probably change before I publish the notebook, so be sure to [lock the imported version](https://observablehq.com/@observablehq/version-locking-for-notebook-imports).

---

<div class="post-metadata">

**Author:** ![neocarto](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/neocarto/32/6554_2.png) [@neocarto](https://talk.observablehq.com/u/neocarto)\
**Post date:** [May 20, 2022, 3:04pm UTC](https://talk.observablehq.com/t/quarto-module-require/6573/3 "2022-05-20T15:04:35Z")

</div>

> <https://github.com/quarto-dev/quarto-cli/issues/943#issuecomment-1133004747>
>
> I have noticed some errors concerning the import of libraries. For example, req…uire("bertin") does'nt work in \[Quarto\](https://quarto.org/docs/tools/rstudio.html). The following error is returned: OJS Error. RequireError$1: invalid module. To import bertin, I have to write: bertin = import('https://cdn.skypack.dev/bertin@0.9'). However, require("bertin") works in Observable. Within rstudio, preview in Viewer Pane works. Preview in window doesn't work. Similarly, the html file rendered via quarto render works. 
> !\[Screenshot from 2022-05-19 10-53-08\](https://user-images.githubusercontent.com/8111373/169254224-e7006ba1-9b00-4bec-afde-a08ab8e77fe9.png)
> 
> Code to reproduce the bug (within an ojs cell).
> (ubuntu 22.04, Rstudio 2022.06.0-daily+420, Quarto 0.9.434)
> 
> \`\`\`\`
> \`\`\`{ojs}
> bertin = require("bertin@0.9.16")
> \`\`\`
> \`\`\`\`

---

<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:** [May 20, 2022, 7:31pm UTC](https://talk.observablehq.com/t/quarto-module-require/6573/4 "2022-05-20T19:31:54Z")

</div>

@neocarto Is your question specifically about RStudio? Because I don’t see how updating Chrome in a desktop software would fix the OJS error in the web version at [Combining R & Observable javascript with Quarto](https://neocarto.github.io/Quarto/)

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/0/01ef5dcb3259198ae99ec75f59a55520aa7dd93e.png)

---

<div class="post-metadata">

**Author:** ![neocarto](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/neocarto/32/6554_2.png) [@neocarto](https://talk.observablehq.com/u/neocarto)\
**Post date:** [May 23, 2022, 8:39am UTC](https://talk.observablehq.com/t/quarto-module-require/6573/5 "2022-05-23T08:39:25Z")

</div>

Yes it’s about Rstudio actually.  
See [OJS Error. RequireError$1: invalid module. · Issue #943 · quarto-dev/quarto-cli · GitHub](https://github.com/quarto-dev/quarto-cli/issues/943)

---

<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:** [May 23, 2022, 11:27am UTC](https://talk.observablehq.com/t/quarto-module-require/6573/6 "2022-05-23T11:27:23Z")

</div>

Interestingly, quarto-cli uses a fork of d3-require that attempts to handle multiple conflicting module loaders:

> **[GitHub - quarto-dev/external-d3-d3-require: A minimal, promise-based...](https://github.com/quarto-dev/external-d3-d3-require)**
>
> A minimal, promise-based implementation to require asynchronous module definitions. - GitHub - quarto-dev/external-d3-d3-require: A minimal, promise-based implementation to require asynchronous mod...

which is based on the branch [GitHub - d3/d3-require at mbostock/restore-define](https://github.com/d3/d3-require/tree/mbostock/restore-define)
