Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

"App: Unhandled exception: TypeError: Expected a function." FS module change?

In all my apps and watch faces when accessing file system I've always used import * as fs from 'fs' and it worked fine. However during the current development I encountered an error "App: Unhandled exception: TypeError: Expected a function". I pinpointed it to FS module. Turns out FS module returns an object named 'default' and now to access any method I need to specify it as fs.default (eg. fs.default.writeFileSync). I don't understand why it's happening. To be on a safe side I created a fail-safe to switch to the 'fs.default' object if fs is unavailable. I installed the watch face on my Ionic and it sure enough does select fs.default instead of good old fs. I'm really confused as in other apps it still works as API documentation specifies (all methods are directly on fs).

Has anyone seen this issue before?

Best Answer
0 Votes
3 REPLIES 3

I don't know what I'm talking about, but I think there might have been a recent change in the build process that is more stringent in the way that things are imported. It's possible that reverting to a previous SDK version might avoid the issue.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

I'm actually using SDK 4.2.0... I did check the SDK 5 and it seems like that one supports both: 'fs' and 'fs.default'. Really strange behavior. 

Best Answer
0 Votes

Hello @ThorgalA! Try changing to 

import fs from 'fs'

In now the new version 4.3.0

 

 

If this answer works please mark this post as a Best Answer.  ~ K.K Designs

Best Answer