mithril.js icon indicating copy to clipboard operation
mithril.js copied to clipboard

Uncaught TypeError: m is not a function

Open designMoreWeb opened this issue 6 years ago • 4 comments

I followed the tutorial and am trying to run the program however i am getting the error in the console:

Uncaught TypeError: m is not a function and the code is `var m = require("mithril")

var UserList = require("./views/UserList") var UserForm = require("./views/UserForm") var Layout = require("./views/Layout")

m.route(document.body,"/list",{ "/list": { render: function () { return m(Layout, m(UserList)) } }, "/edit/:id": { render: function (vnode) { return m(Layout, m(UserForm, vnode.attrs)) } }, })

`

the error is given by :

return m(Layout, m(UserList))

designMoreWeb avatar Apr 14 '19 18:04 designMoreWeb

Are you using Webpack? If so, try var m = require('mithril').default

osban avatar Apr 14 '19 18:04 osban

thanks it worked

I needed to add

var m = require("mithiril").default to all the js files in order for it to work properly

designMoreWeb avatar Apr 14 '19 18:04 designMoreWeb

Cool 👍 Yeah, all the requires should be like that.

osban avatar Apr 14 '19 19:04 osban

This will be fixed by #2366 once resolved.

dead-claudia avatar Apr 17 '19 17:04 dead-claudia