Unhandled Rejection: default.get is not a function

Asked
Active3 hr before
Viewed126 times

8 Answers

functionrejectionunhandled
90%

Meta Stack Overflow , Stack Overflow Public questions & answers , Stack Overflow help chat

api.js:

const api = axios.get({
   baseURL: 'https://api.covid19api.com',
})
88%

Maybe there is a typo in the function name? Maybe the object you are calling the method on does not have this function? For example, JavaScript Objects have no map function, but the JavaScript Array object does. , Sometimes when making a class, you may have a property and a function with the same name. Upon calling the function, the compiler thinks that the function ceases to exist. , It attempted to call a value from a function, but the value is not actually a function. Some code expects you to provide a function, but that didn't happen.

TypeError: Object doesn 't support property or method {x} (Edge)
TypeError: "x"
is not a
function
load more v
72%

Now run your app again. The error disappears, and your data is parsed through correctly.,Here is a simple React app to simulate fetching data from your API and setting state.,In this tutorial, you will learn why this error occurs and how to fix it. This guide assumes that you have basic knowledge of React.js.

1 {
   2 "page": 1,
      3 "results": [{
            4 "poster_path": "/e1mjopzAS2KNsvpbpahQ1a6SkSn.jpg",
            5 "adult": false,
            6 "overview": "From DC Comics comes the Suicide Squad, an antihero team of incarcerated supervillains who act as deniable assets for the United States government, undertaking high-risk black ops missions in exchange for commuted prison sentences.",
            7 "release_date": "2016-08-03",
            8 "genre_ids": [
               9 14,
               10 28,
               11 80
               12
            ],
            13 "id": 297761,
            14 "original_title": "Suicide Squad",
            15 "original_language": "en",
            16 "title": "Suicide Squad",
            17 "backdrop_path": "/ndlQ2Cuc3cjTL7lTynw6I4boP4S.jpg",
            18 "popularity": 48.261451,
            19 "vote_count": 1466,
            20 "video": false,
            21 "vote_average": 5.91
            22
         },
         23 {
            24 "poster_path": "/lFSSLTlFozwpaGlO31OoUeirBgQ.jpg",
               25 "adult": false,
               26 "overview": "The most dangerous former operative of the CIA is drawn out of hiding to uncover hidden truths about his past.",
               27 "release_date": "2016-07-27",
               28 "genre_ids": [
                  29 28,
                  30 53
                  31
               ],
               32 "id": 324668,
               33 "original_title": "Jason Bourne",
               34 "original_language": "en",
               35 "title": "Jason Bourne",
               36 "backdrop_path": "/AoT2YrJUJlg5vKE3iMOLvHlTd3m.jpg",
               37 "popularity": 30.690177,
               38 "vote_count": 649,
               39 "video": false,
               40 "vote_average": 5.25
            41
         },
         42 {
            43 "poster_path": "/hU0E130tsGdsYa4K9lc3Xrn5Wyt.jpg",
               44 "adult": false,
               45 "overview": "One year after outwitting the FBI and winning the public’s adulation with their mind-bending spectacles, the Four Horsemen resurface only to find themselves face to face with a new enemy who enlists them to pull off their most dangerous heist yet.",
               46 "release_date": "2016-06-02",
               47 "genre_ids": [
                  48 28,
                  49 12,
                  50 35,
                  51 80,
                  52 9648,
                  53 53
                  54
               ],
               55 "id": 291805,
               56 "original_title": "Now You See Me 2",
               57 "original_language": "en",
               58 "title": "Now You See Me 2",
               59 "backdrop_path": "/zrAO2OOa6s6dQMQ7zsUbDyIBrAP.jpg",
               60 "popularity": 29.737342,
               61 "vote_count": 684,
               62 "video": false,
               63 "vote_average": 6.64
            64
         }
         65
      ]
   66
   67
}
load more v
65%

@sumit194 The default restoreOriginalUri callback function uses history API from react-router-dom, have you included the module in your dependencies?,Getting this error while loading the app first time after login redirect, but when manually try to remove the implicit/callback and reload the application it loads fine,@sumit194 The error looks like a module export issue, but I cannot tell how it relevant with override the restoreOriginalUrl callback. Can you try our official sample to see if you can repro the issue there?

const ProtectedRoute = ({ children, ...rest }) => (
  <Suspense fallback={<div>loading...</div>}>
    <OktaComponent {...rest}>{children}</OktaComponent>
  </Suspense>
);

const OktaProvider = (props) => {
  const history = useHistory();
  const oktaAuth = new OktaAuth({
    issuer: config.okta.issuer,
    clientId: config.okta.client_id,
    redirectUri: config.okta.redirect_uri,
    restoreOriginalUri: async (_, originalUri) => {
      history.replace(toRelativeUrl(originalUri, window.location.origin));
    },
  });
  return (
    <Security oktaAuth={oktaAuth}>
      <SecureRoute path="/">
        <ProtectedRoute {...props} />
      </SecureRoute>
      <Route path="/implicit/callback">
        <LoginCallback />
      </Route>
    </Security>
  );
};
75%

We must add a semicolon. Somewhere.,and also this would work:,But it’s not, so we get that ...is not a function error.

This can cause, in some cases, an error like this:

TypeError: require(...) is not a
function
const fs = require('fs')

(async () => {
   //...
})()
const fs = require('fs')

;
(async () => {
   //...
})()
const fs = require('fs');

(async () => {
   //...
})()
load more v
40%

Since React expects a function, it instead gets a Promise and fails.,onChangeContent is not a function/async function. It is an object, specifically a Promise.,The root problem is a misunderstanding of how async functions work.

The root problem is a misunderstanding of how async functions work.

const onChangeContent = async (newUrl) => {

The async and await are just shorthand. These 2 functions are identical:

async function foo() {
   return 1
}

function foo() {
   return Promise.resolve(1)
}

For example, here we fetch posts, display loading status, etc:

import React from 'react';
import apiFetch from '@wordpress/api-fetch';
import { useSelect } from '@wordpress/data';
import { useState, useEffect, useRef } from '@wordpress/element';
import { addQueryArgs } from '@wordpress/url';

function PostList() {
    // are we loading the posts?
    const [ isLoading, setLoading ] = useState( true );
    // the posts we're displaying
    const [ posts, setPosts ] = useState([]);
    // we don't want to update state on an unmounted component
    const isStillMounted = useRef();

    // fetch the posts
    useEffect(() => {
        isStillMounted.current = true;
        apiFetch( {
            path: addQueryArgs( `/wp/v2/posts`, { } ),
        } )
            .then( ( data ) => {
                if ( isStillMounted.current ) {
                    setPosts( data );
                    setLoading( false );
                }
            } )
            .catch( () => {
                if ( isStillMounted.current ) {
                    setPosts( [] );
                    setLoading( false );
                }
            } );
    }, [setPosts, setLoading, isStillMounted]);

    if ( isLoading ) {
        return <div>Loading...</div>;
    }

    return <div>{ .. use posts variable here ... }</div>

}
load more v
22%

Pretag
 Pretag team - issue, fix, solve, resolve
60%

I found the issue, after fetching the first time in the saveplaylist method i didn’t put a then between the jsonResponse and the second fetch. After updating that no more issues. Btw I guess th page has to reload the first time in order to reach the access URL. I hope that might help you,Hello there, I’m almost at the end of the project but I’ve got an error when I try to save the playlist. I realized when the page loads and I try to add a song the page just reloads. When I try that again the song is added. Then when I try to save the playlist I get that error. I believe something goes wrong when it tries to get the accessToken but the code seems fine to me.,This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.

load more v

Other "function-rejection" queries related to "Unhandled Rejection: default.get is not a function"