Mithril.js: Uncaught TypeError: m is not a function

Created on 14 Apr 2019  路  4Comments  路  Source: MithrilJS/mithril.js

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))

Most helpful comment

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

All 4 comments

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

thanks it worked

I needed to add

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

Cool 馃憤
Yeah, all the requires should be like that.

This will be fixed by #2366 once resolved.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marciomunhoz picture marciomunhoz  路  4Comments

hadihammurabi picture hadihammurabi  路  4Comments

omenking picture omenking  路  3Comments

josephys picture josephys  路  4Comments

millken picture millken  路  4Comments