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] Cannot import this module in Typescript #205

Closed
politician opened this issue Apr 27, 2022 · 4 comments
Closed

[BUG] Cannot import this module in Typescript #205

politician opened this issue Apr 27, 2022 · 4 comments
Labels
bug Something isn't working Fund help wanted Extra attention is needed

Comments

@politician
Copy link

politician commented Apr 27, 2022

Describe the bug

When I try to import this module in my typescript project, I get the following error:

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;

To Reproduce

Does not work

import { ImgurClient } from "imgur";

const imgurClient = new ImgurClient({
  clientId: process.env.IMGUR_CLIENT_ID,
  clientSecret: process.env.IMGUR_CLIENT_SECRET,
});

Works

import imgur from "imgur";

const imgurClient = new imgur.ImgurClient({
  clientId: process.env.IMGUR_CLIENT_ID,
  clientSecret: process.env.IMGUR_CLIENT_SECRET,
});

⚠️ However VSCode shows me Property 'ImgurClient' does not exist on type 'typeof ImgurClient'.

Environment

  • Library version: 2.2.0
  • OS: macOS
  • NodeJS version: v16.14.2
@KenEucker KenEucker added help wanted Extra attention is needed bug Something isn't working labels Nov 7, 2022
@Dazaer
Copy link

Dazaer commented Dec 23, 2022

Have you tried import ImgurClient from "imgur"?

This works for a .ts file.

@KenEucker
Copy link
Owner

@politician disregard my previous statement, I ran across this in another project and was able to see the problem. I don't know how to resolve it at the moment, but can you try these lines:

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

And see if you are at least able to use the API? It breaks intellisense, unfortunately, but I have been able to use it without issues at runtme.

@Infinitay
Copy link

Infinitay commented Sep 10, 2023

I ended up having this issue but your suggestion above resolved the import error for me without requiring the typescript ignore comment. However, I was met with another issue:

Error: Cannot find module 'tslib'

Specifically installing tslib into my project solved that. Not sure why I had to explicitly install it into my own project when the imgur package depended on it.

@polar-sh polar-sh bot added the Fund label Jan 19, 2024
@KenEucker
Copy link
Owner

I just pushed a new version (2.4.0) of this package that is built using Vite and should no longer present any issues with importing this module in TypeScript.

Please let me know if you see any further issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fund help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants