Getting mithril js working in a Vite replit

Question:
I have created a Replit with Vite. I installed mithril as a package. I am trying to follow the mithril tutorial. The first thing is says to do is :-

var m = require("mithril")

m.render(document.body, "hello world")

This does not do anything. What am I missing?

:wave: Hey @tjpriley, welcome to the forums!

Can you please provide a link to the Repl? This way it is easier for staff and members of the community to help you! :slight_smile:

Also see this guide on how to share your code:

https://replit.com/@tjpriley/JSandVite

The repl is private. Does that matter?

Yes. I can’t help you if it’s private.

OK, I made it public. Thanks.

a tutorial is making you use CJS for a client-side framework? Try the official tutorial. It might help to view templates, maybe GitHub - BaseMax/MithrilTS-JSX: Create a SPA project using Mithril JS framework and design layout by JSX syntax and use Typescript and Vite for build system.

Thank you.
I am very new to Javascript and struggling to make any sense of it. It feels like I have joined the Empire Strikes Back movie and don’t know why it matters that the guy in the mask is father to the guy he just chopped the hand off.
I was simply attempting to write a SPA in mithril but using Javascript modules. The modules work for me sometimes. Mithril works for me sometimes. But I am stabbing in the dark as to why. What I mean is - I get something simple to work, then I add one more line of code and then nothing works.
The suggestion you offer is probably excellent but is akin to telling me to watch Clone Wars to better understand the lore. Educational in itself but just another set of things I have to learn. I looked it over and it just deepens my confusion as to what is going on. But I truly appreciate the spirit in which it was offered.
I think I need to go away, learn more javascript, and then come back. Thank you.

I got it WORKING!
It was a lack of curly braces on the import. I knew it had to be something simple.

import Splash from "./splash"

This didn’t work. I had to be putting

import {Splash} from "./splash"
2 Likes