What is the name of my Kotlin-generated JavaScript module?

I think the JavaScript module is named “untitled2”, because that’s the project name, as well as the name of the .js file produced in build/js/packages. However, that doesn’t seem to work, or else I misunderstand how to use it.

Scenario 1.

I include the script in the body, and call the function I want from JavaScript’s main(), like so:

fun main() { apply("myCanvas") }

<canvas id="myCanvas" width="400" height="300"></canvas>
<script src="untitled2.js">

Everything works fine.

Scenario 2.

I include the script in the header:

<head> <!-- standard boilerplate omitted -->
<script src="untitled2.js"></script>

When I try to reference this in my HTML file:

<canvas id="myCanvas" width="400" height="300"></canvas>
<button type="button" id="button1" onclick="untitled2.apply('myCanvas')">Plot it</button>

the JavaScript debugger console reports, Can't find variable: untitled2. So apparently that isn’t the module name. Omitting untitled2 also doesn’t work.

How do I determine the module name – or – how do I import it properly? I have read the usual suspects cited here.

(I hope it’s allowed to bump this topic in the hope that someone notices.)


try window.untitled2.

If you have a special character in your module name like ‘-’ then window[‘untitled-2’].

Thank you for the suggestion. After a couple of days with no reply, I just refactored my code to take a different approach, but the approach I use now is arguably suboptimal. I will try to refactor it again at some point & if I do I will report back.

Can you attach a link to your project, please?

I don’t have it on GitHub, and I don’t believe I have a copy of the older code. Do you want a link to a webpage that shows the code in action? (It will also so how I execute it in JavaScript.)

I don’t think this link will help. I failed to reproduce the problem, and it’s hard to help you without a sample project.