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

npm package failing at random part

So I'm trying to use the Ably Realtime npm package but it doesn't seem to work and fails as a very weird place. I have already tried the answers to similar to questions and it doesn't seem to work.

Approaches I have tried as follows and errors for each of them -

1. Importing the package directly using this import statement "import * as Ably from 'ably'; " 

var realtime = new Ably.Realtime('API-key'); 

Error while building is this -

[00:01:20][error][app] Error: Could not load path (imported by /sample-apps/fitbit/samplenewapp/node_modules/ably/nodejs/realtime.js): ENOENT: no such file or directory, open 'path'
Details:
errno: -2
code: PLUGIN_ERROR
syscall: open
path: path
pluginCode: ENOENT
hook: load

 

2. Importing from a file "import * as Ably from './ably';"

var realtime = new Ably.Realtime('API-key'); 

Error while building is this -

app/index.js (4:24) 'Realtime' is not exported by 'ably.js'

 

The same Realtime initialising statement works in React, Javascript etc.

 

3. I even tried what is mentioned here https://community.fitbit.com/t5/SDK-Development/Using-non-ES6-modules/m-p/2972514#M6292

After following that the build was successful but error while running -

App: Unhandled exception: Error: failed to pre-parse snapshot

 

I have been trying to make it work but no success. Would really appreciate help in this please. 

Best Answer
0 Votes
19 REPLIES 19

I don't know how large that JS is, but the device is very limited in terms of memory. Are you doing this in the companion?

Best Answer
0 Votes

@JonFitbit No I'm trying this in main file only. Shouldn't I get a memory error in case of memory issue

Best Answer
0 Votes

You should try to get it working in the companion, the device is probably too constrained. You can then send messages from the device to the companion instructing it to perform actions, or fetch data.

Best Answer
0 Votes

@JonFitbit I'm still facing the same issue , tried with companion as well. 

Got a similar error while building -
[19:13:17][error][companion] Error: Could not load fs (imported by /Users/av/Batman/side-projects/sample-apps/fitbit/samplenewapp/node_modules/ably/nodejs/rest.js): ENOENT: no such file or directory, open 'fs'
Details:
errno: -2
code: PLUGIN_ERROR
syscall: open
path: fs
pluginCode: ENOENT
hook: load

Best Answer
0 Votes

Can you post the project somewhere?

Best Answer
0 Votes

@JonFitbit I have created a repo. You can take a look here https://github.com/vardhanapoorv/fitbit-sample-app . Thanks!

Best Answer
0 Votes

I've submitted a PR. It's slightly weird in that the companion isn't a browser, and it's also not nodejs. I didn't test the comms, but the module imported and isn't complaining.

Best Answer
0 Votes

@JonFitbit thanks a lot for this. So I basically want to use that library to send message on click of the "Click me" button, so I'm not clear how I can do that since that code I cannot add in click event handler in the app "index.js" file. How can I direct the companion to trigger some code on click of that button?

Best Answer
0 Votes

You need to use the Messaging API to send messages from the device to the companion, and vice-versa.

 

https://dev.fitbit.com/build/guides/communications/messaging/

 

Don't forget to add the `access_internet` permission to your app, since you're using it in the companion.

Best Answer
0 Votes

@JonFitbit thanks for that. But I wanted to know the feasibility if I can use Ably library. And one more thing I wanted to know, so I can't use this app alone with the device if I'm using companion right?

Best Answer
0 Votes

The only way for the device to access the internet is via the companion. So you can use the device to drive the behavior and UI of your application, and relay messages via the companion.

Best Answer
0 Votes

@JonFitbit thanks a lot! Will try this approach and let you know if I face further issues. I think I won't be able to run this in the simulator since I need to enable 'access_internet' and I'm getting this in terminal on running -
Companion: The 'permission' API is not yet supported in the Fitbit OS Simulator. Behavior may not match the documentation or real devices.

So, I think I will have to try this a fitbit device.

Best Answer
0 Votes

I think you can ignore that simulator warning. All permissions are granted automatically; the sim can definitely access the internet.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

@Gondwana thanks!
@JonFitbit thanks a lot, finally got it working!!!
Had a question so every npm package kind of will have a import statement like this "ably/browser/static/ably-commonjs.js" for it to work in companion and is there any documentation specifying this way of using a lib. 

Best Answer
0 Votes

@JonFitbit so I completed the clockface and its working perfectly on the simulator. Now I want to test on a really Fitbit watch so for that I uploaded the project in the studio but it isn't working there.
First I got an error parsing tsconfig.json so I deleted the file just to check the issue. Then I got an error in the import statement which you helped me with in the PR "ably/browser/static/ably-commonjs.js is imported by companion/index.js, but could not be resolved" .
So if it doesn't work in the studio how can I make it work on the watch. Is there someway I can directly put it on the watch?

Hope to hear from you really soon.
@Gondwana if you can help please let me know.Screenshot 2020-01-02 at 7.00.21 PM.pngScreenshot 2020-01-02 at 7.00.56 PM.png

Best Answer
0 Votes

Studio doesn't support npm packages, but you don't need Studio if you're already using the CLI.

 

Just quit the simulator, enable developer bridge on your Fitbit device, and phone, then the CLI will use those devices when you install.

Best Answer
0 Votes

Thanks @JonFitbit for the help.

Best Answer
0 Votes

@JonFitbit so I tried that and I'm facing few issues. Like I'm getting this error (refer attachment) the first time I ran it but not after that. Plus I have 3 settings, but only one setting is showing (remaining settings should show up after first setting is filled since they're dependent on that) . 

 

 

Image from iOS.pngScreenshot 2020-01-17 at 17.36.43.png

Best Answer
0 Votes

We definitely don't have a navigator object since it's not a browser environment. I wonder if you could declare your own at the global scope. I'm not sure what Ably does with that variable though, or if it's required.

Best Answer
0 Votes