node-strava/node-strava-v3

[BUG] TypeError: Cannot read properties of undefined (reading 'config')

elendil7 opened this issue · 1 comments

Description

When importing as follows, the types get imported but I get an error at runtime.:

import { default as strava, Strava } from "strava-v3";
import strava from "strava-v3";

The error is as follows:
TypeError: Cannot read properties of undefined (reading 'config')

I have managed to fix it by importing the module using commonjs require as follows:

const strava = require('strava-v3')

However, this stops intellisence autocomplete from working with the library. Hence, I'd like to know if there's a way to fix this issue (when importing as typescript module).

Observations

When console.logging "strava" after importing it, it prints "undefined".

import { default as strava, Strava } from "strava-v3";
console.log(strava);

Other info

  • node-strava-v3 version: ^2.2.0

Update

Fixed using a hacky workaround by:

  • Importing strava-v3 commonjs module using require
  • Importing Strava interface using esm module import
  • Specifying my client as type Strava

Code

const strava = require("strava-v3");
import { Strava } from "strava-v3";

export default class StavaService {
  private client: Strava;
  private config: typeof config_STRAVA;
  private CLIENT_ID: string;
  private CLIENT_SECRET: string;
  private ACCESS_TOKEN: string;

  constructor() {
    this.client = strava;
    this.config = config_STRAVA;
    this.CLIENT_ID = STRAVA_CLIENT_ID;
    this.CLIENT_SECRET = STRAVA_CLIENT_SECRET;
    this.ACCESS_TOKEN = STRAVA_ACCESS_TOKEN;
    this.init();
  }
}