Question: should elm-repl work with native modules present? I get window is not defined when trying to import something that has them

Asked By
risto.helinko
Asked At
2018-03-20 11:55:46

Found 15 possible answers.

User Answered At Possible Answer
norpan 2018-03-20 11:58:37 @risto.helinko what module? I think you should ask the module author native modules are basically just javascript, so if that javascript tries to access window (which is not defined in elm-repl, obviously) then it will not work
risto.helinko 2018-03-20 12:00:22 it's elm-storage-local
norpan 2018-03-20 12:01:24 yes, so it tries to access window.localStorage, which is not defined obviously. broken module in elm-repl
risto.helinko 2018-03-20 12:03:11 I guess I need to see if I can work around this by editing the imports unless there's a way to make the repl ignore that error?
norpan 2018-03-20 12:04:42 I have no idea, but you could edit the module to check for the existence of window before trying to use it
  just set this to
var available = window && !!window.localStorage;
risto.helinko 2018-03-20 12:07:36 hmm, that still gives the same error
norpan 2018-03-20 12:08:36 that’s strange, did you change in the right place? You may need to recompile, remove elm-stuff/build-artifacts
risto.helinko 2018-03-20 12:12:03 the error does quote the new version of that, but it's still referring to window which doesn't exist
norpan 2018-03-20 12:14:32 oh maybe it’s using strict mode, then try
var available = typeof window != 'undefined' && !!window.localStorage;
juanchoalcantaraborja 2018-03-20 12:25:09 Hi everyone!
risto.helinko 2018-03-20 12:32:47 it just pushes the error further :confused: I think I'm gonna try to run the code from unit tests instead, but thanks anyways!
norpan 2018-03-20 12:33:50 well this is a problem with native code, you are probably better of using ports
anttila 2018-03-20 12:49:58 What's this format really? 2018-01-16T10:37:44.000Z Ok, so it's ISO 8601 (and can it be easily formatted to something else)
norpan 2018-03-20 13:10:00 ISO 8601 :heart:
anttila 2018-03-20 13:39:51 |> Maybe.map (DateFormat.format DateConfig.config "%d.%m.%Y") if only people knew how to calculate unix timestamps... why can't everyone use the same standards

Related Questions