Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spotify_web_api_node_1.default is not a constructor #457

Open
Arkmind opened this issue May 25, 2022 · 3 comments
Open

spotify_web_api_node_1.default is not a constructor #457

Arkmind opened this issue May 25, 2022 · 3 comments

Comments

@Arkmind
Copy link

Arkmind commented May 25, 2022

Versions :

{
  "spotify-web-api-node": "^5.0.2",
  "@types/spotify-web-api-node": "^5.0.7",
}

Environment :
NestJS (https://docs.nestjs.com/)

Code of the Service :

import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import SpotifyWebApi from 'spotify-web-api-node';
import { PrismaService } from 'src/prisma.service';

@Injectable()
export class OAuthService {
  public client: SpotifyWebApi;

  constructor(prismaService: PrismaService, configService: ConfigService) {
    this.client = new SpotifyWebApi({
      clientId: configService.get<string>('SPOTIFY_CLIENT_ID'),
      clientSecret: configService.get<string>('SPOTIFY_CLIENT_SECRET'),
      redirectUri: configService.get<string>('SPOTIFY_REDIRECT_URI'),
    });
  }
}

Error :

spotify_web_api_node_1.default is not a constructor
TypeError: spotify_web_api_node_1.default is not a constructor
    at new OAuthService (/src/oauth/oauth.service.ts:11:19)
    at Injector.instantiateClass (/node_modules/@nestjs/core/injector/injector.js:330:19)
    at callback (/node_modules/@nestjs/core/injector/injector.js:48:41)
    at Injector.resolveConstructorParams (/node_modules/@nestjs/core/injector/injector.js:122:24)
    at Injector.loadInstance (/node_modules/@nestjs/core/injector/injector.js:52:9)
    at Injector.loadProvider (/node_modules/@nestjs/core/injector/injector.js:74:9)
    at async Promise.all (index 5)
    at InstanceLoader.createInstancesOfProviders (/node_modules/@nestjs/core/injector/instance-loader.js:44:9)
    at /node_modules/@nestjs/core/injector/instance-loader.js:29:13
    at async Promise.all (index 1)

How to reproduce :
Create new service containing SpotifyWebApi and launch the app

@Arkmind
Copy link
Author

Arkmind commented May 25, 2022

In order to fix it temporarly you can use

"esModuleInterop": true

in your tsconfig.json

@alexhito
Copy link

alexhito commented Jun 23, 2022

I fixed this like so:
import SpotifyWebApi = require('spotify-web-api-node');

@nodgear
Copy link

nodgear commented Jul 25, 2022

I fixed this like so: import SpotifyWebApi = require('spotify-web-api-node');

this syntax doesn't even make sense

you either import it with ES6 (import {} from '')
or ESM (require())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants