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

[BUG] TypeError: ImgurClient is not a constructor #214

Closed
pkdev08 opened this issue Jan 6, 2023 · 4 comments
Closed

[BUG] TypeError: ImgurClient is not a constructor #214

pkdev08 opened this issue Jan 6, 2023 · 4 comments

Comments

@pkdev08
Copy link

pkdev08 commented Jan 6, 2023

import ImgurClient from 'imgur';

const client = new ImgurClient({
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET
});

Gives error TypeError: ImgurClient is not a constructor

On LTS node 18.12.1 using ESM

@KenEucker
Copy link
Owner

@pkdev08 you need to deconstruct the ImgurClient type, as shown in the documentation:

// ESModule syntax
import { ImgurClient } from 'imgur';

@pkdev08
Copy link
Author

pkdev08 commented Jan 16, 2023

@pkdev08 you need to deconstruct the ImgurClient type, as shown in the documentation:

// ESModule syntax
import { ImgurClient } from 'imgur';

Hi, when I do that it's having export issues.

import { ImgurClient } from 'imgur';
^^^^^^^^^^^
SyntaxError: Named export 'ImgurClient' not found. The requested module 'imgur' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'imgur';
const { ImgurClient } = pkg;

@KenEucker
Copy link
Owner

@pkdev08 can you try the following lines:

import imgur from 'imgur'
// @ts-expect-error
const ImgurClient = imgur.ImgurClient

I started running into this error in another project and I have now realized that esm imports do not work as intended, which was the primary target for this library. I will try to find a way to resolve this in the export, maybe by moving to rollup, as soon as I am able to.

@KenEucker
Copy link
Owner

I just realized that this was also pointed out in a previous issue, so I am closing this ticket as it is a duplicate of the issue in #205.

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

2 participants