1

In a react app, I have some business logic I'm trying to encapsulate in class called Authentication. When I try to call a method called configure on the Authentication class I get the following error:

TypeError: WEBPACK_IMPORTED_MODULE_5__authentication_js.a.configure is not a function

In my React app.js file I import the authentication class with:

import Authentication from './authentication.js';

and then I try to access it inside my constructor as follows:

constructor(props) {
    super(props);
    Authentication.configure();
}

The code for authentication.js is as follows:

class Authentication {

  constructor(props) {
    console.log('inside constructor of Authentication class');    
  }

  configure(){
    //some setup logic, still fails if I comment it all out
  }
}
export default Authentication;

I'm unsure how exactly to troubleshoot this issue. I know I've seen similar issues in react before where an internal method has not had the bind method called against it, but I'm unsure if that is needed for a public method of an external class and if it is required, I'm not sure how to implement it. Any help/guidance would be greatly appreciated.

1 Answer 1

2

configure is an instance method of the Authentication class.

Either make configure static, or export an instance of Authentication.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! I was over complicating this in my mind.
Wow, same error, same flow (I've written an auth helper class). Thanks for the answer!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.