admin管理员组

文章数量:1122846

I'm working in RStudio and am instructing knitr to include a JavaScript code chunk:

```{js, echo=FALSE}
import { MyModule } from './js/mymodule.js';

[other code]
 
```.

However, the JS engine is throwing an import error because I need the opening <script> tag to contain the attribute type="module". Is there a way I can have knitr automatically add this attribute for me instead of putting in by hand in the resulting HTML file?

I'm working in RStudio and am instructing knitr to include a JavaScript code chunk:

```{js, echo=FALSE}
import { MyModule } from './js/mymodule.js';

[other code]
 
```.

However, the JS engine is throwing an import error because I need the opening <script> tag to contain the attribute type="module". Is there a way I can have knitr automatically add this attribute for me instead of putting in by hand in the resulting HTML file?

Share Improve this question asked Nov 21, 2024 at 19:24 TobyRushTobyRush 7565 silver badges21 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

I'd suggest that you write the <script> tag directly, since it's not much extra typing effort, and raw HTML elements work fine in Markdown.

<script type="module">
import { MyModule } from './js/mymodule.js';

[other code]
</script>

本文标签: htmlIs there a way in knitr to add an attribute to a script tagStack Overflow