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] Error when using ES Modules with Jimp #1284

Open
jynxio opened this issue Mar 15, 2024 · 6 comments · May be fixed by #1285
Open

[BUG] Error when using ES Modules with Jimp #1284

jynxio opened this issue Mar 15, 2024 · 6 comments · May be fixed by #1285

Comments

@jynxio
Copy link

jynxio commented Mar 15, 2024

Expected Behavior

Performing a get operation on Jimp.


Current Behavior

The program throws an error.


Failure Information (for bugs)

If you use CommonJS syntax to import and access Jimp, no error will occur.

If you use ES Modules syntax to import and access Jimp, an error will be thrown, with the error message: Uncaught TypeError: Class extends value [object Object] is not a constructor or null (at chunk-445PKJEV.js?v=ab5727de:26240:46).


Steps to Reproduce

Step 1: Install the dependencies;

npm i --save jimp

Step 2: Import and access

import Jimp from 'jimp/es';
Jimp; // 😥 This will throw an error

I also tried import Jimp from 'jimp'import * as Jimp from 'jimp'import * as Jimp from 'jimp/es', and they all result in the same error.


Context

  • Jimp Version: 0.22.12
  • Operating System: Windows 10
  • Node version: v21.5.0
  • Browser: Chrome 121.0.6167.140 (64-bit)
@jynxio
Copy link
Author

jynxio commented Mar 15, 2024

To supplement, using CommonJS to import and access Jimp in Node.js does not cause any errors. The code is as follows:

const Jimp = require('jimp');
Jimp; // 👌 All is well

@rehanvdm
Copy link

Same issue and I can't use require

@hipstersmoothie
Copy link
Collaborator

I've been working on v1 and it should support cjs/esm/browser in a much more modern (and working) way

@hipstersmoothie hipstersmoothie linked a pull request Mar 28, 2024 that will close this issue
@rehanvdm
Copy link

That's great to hear thank you :)

Do you have a tentative timeline, days, weeks, months? From the last commits on that branch, it looks close to done.

@hipstersmoothie
Copy link
Collaborator

It is pretty close to done. I think by end of the week

@rehanvdm
Copy link

rehanvdm commented Apr 2, 2024

Sounds good. Just to report back, for others that might follow, when I updated my packages I first updated minor + patch and tested before updating major packages. Jimp was one of the minor packages and vite aka esbuild, was one of the major ones. Once I updated both to the latest versions it worked. I just had to change the import to:

import Jimp from 'jimp';

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

Successfully merging a pull request may close this issue.

3 participants