Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Cannot use m directly, m.default is required #28

Closed
ciscoheat opened this issue May 10, 2018 · 5 comments
Closed

Cannot use m directly, m.default is required #28

ciscoheat opened this issue May 10, 2018 · 5 comments

Comments

@ciscoheat
Copy link

import * as m from 'mithril'
m.render(document.body, m('h1',  'Test'))

Gives the following errors:

TS7038: A namespace-style import cannot be called or constructed, and will cause a failure at runtime.
TS2349: Cannot invoke an expression whose type lacks a call signature. Type '{ default: Static; route: Route; mount: { (element: Element, component: ComponentTypes<any, any>)...' has no compatible call signatures.

using m.default('h1', 'Test') instead works.

@ciscoheat
Copy link
Author

using import m from 'mithril' also works.

@spacejack
Copy link
Collaborator

This depends on your bundler setup, and yes we should add some notes about this to the readme. I believe with rollup you enable allowSyntheticDefaultImports in tsconfig and use import m. With Browserify I use import * as m. This is how imports worked in webpack as well but I haven't tried it recently.

What bundler are you using?

@ciscoheat
Copy link
Author

Thanks for the info, I'm using webpack 4.8.1, with typescript 2.8.3 and the latest Mithril types. It is a bit confusing, some notes would be much appreciated even though it's not Mithrils fault!

@spacejack
Copy link
Collaborator

Closing as this should be addressed in the readme now.

@t3hmrman
Copy link

t3hmrman commented Jan 23, 2019

Hey this is still an issue, even when I follow what's in the README -- in particular with rollup.

Rollup doesn't plan on fixing this, given this issue thread -- neither import * as m from 'mithril' or import m from 'mithril' work. I want to note that this does work if you only run tsc.

I did try the xProxy trick from the issue thread but Rollup will complain at you with this error:

default is not exported by node_modules/mithril/mithril.js
1: import * as mithrilProxy from 'mithril';
2: var m = mithrilProxy.default || mithrilProxy;
                        ^
3: // import hack (https://github.com/rollup/rollup/issues/1267#issuecomment-296395734)

Right now I'm getting around this by just using mithril's minified version as an external dependency and ignoring rollup's warning

[EDIT] - I just decided to switch to ParcelJS -- it works much easier, and supports most of the stuff rollup does now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants