dkuku
Js is not my strongest skill and I can’t find this in the kino examples.
Every time I wan’t to include js it only works for me inside a callback function that I pass to the promise. With one included file it’s fine but with multiple it becomes tricky.
Importing on top of the file does not work with every kind of js file like in the mermaid example.
If I try to import the url that is provided in the importJS in the example below it throws an error in the js.
I tried the same with pev2 package and I have similar problem there.
defmodule VlBlockly do
use Kino.JS
def new(toolbox) do
Kino.JS.new(__MODULE__, toolbox)
end
asset "main.js" do
"""
const blockyRoot = '<div id="blocklyDiv" style="height: 480px; width: 600px;"></div>'
export function init(ctx, toolbox) {
ctx.importJS("https://unpkg.com/blockly/blockly.min.js").then(() => {
load(ctx, toolbox)
})
}
const load = (ctx, toolbox) => {
ctx.root.innerHTML = blockyRoot;
const workspace = Blockly.inject('blocklyDiv', {toolbox: JSON.parse(toolbox)});
}
"""
end
end
toolbox =
%{
contents: [
%{kind: "block", type: "text"},
%{kind: "block", type: "text_print"}
],
kind: "flyoutToolbox"
}
|> Jason.encode!()
VlBlockly.new(toolbox)
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming











Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
jonatanklosko
@dkuku so the confusion is around importing multiple dependencies with
importJS? You could import the second file inside the callback, but to avoid nesting you can doasync/await. Like this:If you run into any errors, please include those : )
Sidenote, you don’t need to use
Jason, the payload is automatically serialized and deserialized!Yeah, it depends on how the package is distributed. Top-level import works fine for ES modules, but some packages expect to be loaded via
<script>tag, which is exactly whatimportJSdoes.In more complex cases you can also consider using a JS bundler as in a regular JS project.
dkuku
Thanks for the hints
dkuku
@jonatanklosko
I wonder if having a html asset would not make things easier here? Then the scripts can be embedded directly in the html. rit would be easier to mirror the examples from the web. Building the initial root layout could be also simplified.
jonatanklosko
@dkuku there is
Kino.HTMLfor some range of use cases, but most of the time we use the JSinitfunction as an entry point, because it receives data from the Elixir side.adolfont
This thread was very useful.
I was also able to use p5.js (a JavaScript library for creative coding) inside Livebook. In really don’t know if I can do much more than that.
https://twitter.com/adolfont/status/1655554171867627521