lucahuy
lucahuy

Reputation: 800

TypeError: default is not a function. Import, export JavaScript class

I'm having a confusion over this supposed to be simple code:

In driveApi.js:

class GoogleDriveApis {
  constructor(arg) { 
    this.path = arg
  }

  test() {
    console.log(this.path)
  }
}
export default new GoogleDriveApis();

When I do:

import GoogleDriveApis from './driveApis'

GoogleDriveApis('abc').test()

I've got this error: TypeError: (0 , _driveApis2.default) is not a function

What did I do wrong?

Upvotes: 1

Views: 4645

Answers (1)

Alon Shmiel
Alon Shmiel

Reputation: 7121

Remove this: export default new GoogleDriveApis();

and change your class to be: export default class GoogleDriveApis {

Upvotes: 3

Related Questions