Auth0 Home Blog Docs

auth0Client is undefined in my app

Hello there, I’m in big trouble to find a way to put Auth0 in my app,

I feel like I have made everything to make it work but it’s still not.

My error is TypeError: auth0Client is undefined and this happens when my login button tries to call loginWithRedirect function from the Auth0Provider. I can assume that the provider isn’t well implemented in the code. I tried many ways with the Auth0 React SDK Quickstart to make it work, but since I am in typescript, this makes it a little harder.

Here is a sample of my code where the Auth0Provider is implemented.

            ReactDOM.render(
            <Auth0Provider
                domain={'mydomain'}
                client_id={'anything'}
                redirect_uri={window.location.origin}
                onRedirectCallback={onRedirectCallback}
            >
              <Provider store={store}>
                <MuiThemeProvider theme={theme}>
                    <BrowserRouter>
                            <App/>
                    </BrowserRouter>
                </MuiThemeProvider>
              </Provider>
            </Auth0Provider>
       ,
        document.querySelector('#reactroot'),
      );

I really need help on this one because this is taking way too much time as it should.
Thank you.

1 Like

Hello 1465334, and welcome to the community! :partying_face:

This is often caused by a configuration issue. Please refer to this post: In Auth0-SPA-JS, why does the Auth0Client object take a long time to initialize? as it is a similar issue and the steps provided there may help you.

Please let me know if that helps.

1 Like

Hi Thomas,

I’ve suceed to make it work once, but right after that, it is still doing a similar error which is : Uncaught (in promise) TypeError: auth0_spa_js_1.default is not a function.
It says the error is when createAuth0Client() is called.
I made some research all over google and in every possible solution, they all converge some tsconfig options which seem to not work for me.

Here are some traces of the errors which you may want to take a look.

The line 44 where the error is thrown, which is the createAuth0Client(initOptions) call.


This is when I click on the login button of my page and loginWithRedirect is called from the auth0Client.

I’ve also console log most of my initOptions and variables that auth0 needs and they are all correct.

I must admit this is a really hard one to troubleshoot.

Did you try esModuleInterop: true per the FAQ? https://github.com/auth0/auth0-spa-js/blob/master/FAQ.md#why-do-i-get-auth0_spa_js_1default-is-not-a-function-when-using-typescript

I think you’re on the right path with it being an issue with tsconfig. Have you worked through all the options in this thread? https://github.com/auth0/auth0-spa-js/issues/99

If you have and none of them work, I suggest opening a new issue on the repo.