question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: spotifyApi.createAuthorizeURL is not a function

See original GitHub issue

I recently my project (that has been dormant for a while) from version 4.0.0 to version 5.0.0 of your wonderful project. It seemed to work fine at first, but when running the frontend, it get an TypeError: spotifyApi.createAuthorizeURL is not a function.

I have initialised the library as below:

const spotifyApi = new SpotifyWebApi({
  clientId: process.env.REACT_APP_SPOTIFY_CLIENT_ID,
  redirectUri: redirectUri,
});

export default spotifyApi;

export const createAuthorizeURL = (): string => {
  const newState = generateRandomString(16);
  localStorage.setItem('authState', newState);
  return spotifyApi.createAuthorizeURL(scopes, newState);
};

I could not find anything about this specific error in the changelog, existing issues or the current documentation. Did I miss anything?

If I downgrade to 4.0.0 again it works without any other change.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:10
  • Comments:7

github_iconTop GitHub Comments

8reactions
ssubhamcommented, Apr 16, 2021

Looks like the server methods are missing. This is my 1am fix if you don’t want to downgrade:

npm i spotify-web-api-node
npm i @types/spotify-web-api-node --save-dev
import SpotifyWebApi from 'spotify-web-api-node';
import SpotifyWebApiServer from 'spotify-web-api-node/src/server-methods';

// (...)

// add server methods to client methods   
(SpotifyWebApi as unknown as { _addMethods: (fncs: unknown) => void })._addMethods(SpotifyWebApiServer);
this._api = new SpotifyWebApi();
this._api.createAuthorizeURL()

(taken from source: https://github.com/thelinmichael/spotify-web-api-node/blob/2785f79d58a9017e9f57fbb0f06e6d23022fd3b4/src/server.js) Obviously this is an unofficial fix and may break in the future. (works for 5.0.2)

Thanks for sharing this code. Can you tell me how can i add this in reactjs as it is js not Typescript?

4reactions
TheDeltacommented, Mar 8, 2021

Looks like the server methods are missing. This is my 1am fix if you don’t want to downgrade:

npm i spotify-web-api-node
npm i @types/spotify-web-api-node --save-dev
import SpotifyWebApi from 'spotify-web-api-node';
import SpotifyWebApiServer from 'spotify-web-api-node/src/server-methods';

// (...)

// add server methods to client methods   
(SpotifyWebApi as unknown as { _addMethods: (fncs: unknown) => void })._addMethods(SpotifyWebApiServer);
this._api = new SpotifyWebApi();
this._api.createAuthorizeURL()

(taken from source: https://github.com/thelinmichael/spotify-web-api-node/blob/2785f79d58a9017e9f57fbb0f06e6d23022fd3b4/src/server.js) Obviously this is an unofficial fix and may break in the future. (works for 5.0.2)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Displaying permissions with spotify-web-api-node
Correct, Im using the createAuthorizeURL. It's as follows 'var authorizeURL = spotifyApi.createAuthorizeURL(scopes);'. Where scopes is an array ...
Read more >
spotify-web-api-node.SpotifyWebApi.createAuthorizeURL ...
Creates URL for users to authenticate * @param {String[]} scopes * @param {String} state * @return {String} authorizeUrl */ createAuthLink(scopes,state ...
Read more >
Cannot authenticate to Spotify API with Node.JS app
My problem is that I cannot obtain an access token with the /authorize endpoint. Here's my code : function getToken() ...
Read more >
spotify-web-api-node - npm
// Get Elvis' albums spotifyApi.getArtistAlbums('43ZHCT0cAZBISjO8DG9PnE').then( function( ...
Read more >
JavaScript : 'TypeError: is not a function' in Node.js - YouTube
JavaScript : ' TypeError : is not a function ' in Node.js [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] JavaScript ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found