JAMMMING - Uncaught TypeError: Cannot read properties of undefined (reading 'then') - savePlaylist

I am getting

App.js:51 Uncaught TypeError: Cannot read properties of undefined (reading ‘then’)
at App.savePlaylist (App.js:51:1)

when I try to click the save playlist to spotify button and cannot figure out the issue with my code.

savePlaylist(name, trackUris){

        if(!name || !trackUris.length) {



        const accessToken = Spotify.getAccessToken();

        const headers = { Authorization: `Bearer ${accessToken}`}

        let userId;

        return fetch('https://api.spotify.com/v1/me', { headers: headers }

        ).then(response => response.json()

        ).then(jsonResponse =>{

            userId = jsonResponse.id;

            return fetch(`https://api.spotify.com/v1/users/${userId}/playlists`,


                headers: headers,

                method: 'POST',

                body: JSON.stringify({ name: name })

            }).then(response => response.json()

            ).then(jsonResponse => {

                const playlistId = jsonResponse.id;

                return fetch(`https://api.spotify.com/v1/users/${userId}/playlists/${playlistId}/tracks`, {

                    headers: headers,

                    method: 'POST',

                    body: JSON.stringify({ uris: trackUris })





    const trackURIs = this.state.playlistTracks.map(track => track.uri);

    Spotify.savePlaylist(this.state.playlistName, trackURIs).then(() =>{


        playlistName: 'New Playlist',

        playlistTracks: []




The rest of the code can be found here: GitHub - Crypto-Advisor/jammming


This error can occur if you don’t specify a playlist name or if trackUris is empty, because in those cases you are returning undefined from savePlaylist. But the code in App.savePlaylist expects a promise.
Try returning Promise.reject() (Promise.reject() - JavaScript | MDN) from savePlaylist on bad input.