jimp icon indicating copy to clipboard operation
jimp copied to clipboard

[BUG] Error when using ES Modules with Jimp

Open jynxio opened this issue 2 years ago • 6 comments

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 avatar Mar 15 '24 04:03 jynxio

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

jynxio avatar Mar 15 '24 04:03 jynxio

Same issue and I can't use require

rehanvdm avatar Mar 28 '24 03:03 rehanvdm

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

hipstersmoothie avatar Mar 28 '24 19:03 hipstersmoothie

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.

rehanvdm avatar Mar 29 '24 18:03 rehanvdm

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

hipstersmoothie avatar Apr 02 '24 18:04 hipstersmoothie

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';

rehanvdm avatar Apr 02 '24 18:04 rehanvdm

:rocket: Issue was released in v1.0.2 :rocket:

hipstersmoothie avatar Aug 31 '24 22:08 hipstersmoothie