garmin-connect icon indicating copy to clipboard operation
garmin-connect copied to clipboard

Error importing module on React

Open Risath18 opened this issue 3 years ago • 5 comments

I received this error when running this line of code: image

Here is the error: image image

Any suggestions on how to fix this? I've followed the "How to use" section on the readme, but it seems to not work. Not sure if this is a react-specific error.

Here is my full code:

import './App.css';

const { GarminConnect } = require('garmin-connect');

// Has to be run in an async function to be able to use the await keyword
const main = async () => {
    // Create a new Garmin Connect Client
   // const GCClient = new GarminConnect();

    // Uses credentials from garmin.config.json or uses supplied params
    // await GCClient.login('[email protected]', 'MySecretPassword');

    // // Get user info
    // const info = await GCClient.getUserInfo();

    // // Log info to make sure signin was successful
    // console.log(info);
};

// Run the code

function App() {
  main();

  return (
    <Watch></Watch>
  );
}

export default App;

Risath18 avatar Jul 09 '21 21:07 Risath18

Not Garmin connect related your just not importing "Watch" I think.

On Fri, 9 Jul 2021, 22:44 Risat Haque, @.***> wrote:

I received this error when running this line of code: [image: image] https://user-images.githubusercontent.com/66147598/125138388-c9968580-e0cb-11eb-8d13-cc1e86344207.png

Here is the error: [image: image] https://user-images.githubusercontent.com/66147598/125138422-d74c0b00-e0cb-11eb-9eb8-e6f620a50033.png [image: image] https://user-images.githubusercontent.com/66147598/125138444-df0baf80-e0cb-11eb-8be1-4b6c11aed830.png

Any suggestions on how to fix this? I've followed the "How to use" section on the readme, but it seems to not work. Not sure if this is a react-specific error.

Here is my full code:

import './App.css';

const { GarminConnect } = require('garmin-connect');

// Has to be run in an async function to be able to use the await keyword const main = async () => { // Create a new Garmin Connect Client // const GCClient = new GarminConnect();

// Uses credentials from garmin.config.json or uses supplied params
// await ***@***.***', 'MySecretPassword');

// // Get user info
// const info = await GCClient.getUserInfo();

// // Log info to make sure signin was successful
// console.log(info);

};

// Run the code

function App() { main();

return ( <Watch></Watch> ); }

export default App;

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Pythe1337N/garmin-connect/issues/19, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACMZM6ODEJI7H4CNJ57KA3TW5URZANCNFSM5ADPTMWA .

pauly avatar Jul 10 '21 09:07 pauly

Sorry, the watch import got cut from the code. It gives me the same error even with the import.

Risath18 avatar Jul 10 '21 21:07 Risath18

Did you npm install garmin-connect? doesn't seem to be a React specific thing. This repo has not been working for me though since the Garmin website update two months ago.

pauly avatar Jul 11 '21 07:07 pauly

Yeah, i've done that already. Still not working

Risath18 avatar Jul 12 '21 15:07 Risath18

This package should run server-side and is not really designed to be used with React, which might be why you get some errors. The error itself is referencing code that is not part of garmin-connect.

Also, running an async function like that in a functional component will probably cause errors anyway. You can add an async componentDidMount (for class components) or use the useEffect hook to fetch data asynchronously.

Pythe1337N avatar Aug 11 '21 08:08 Pythe1337N