[BUG] Error when using ES Modules with Jimp
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)
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
Same issue and I can't use require
I've been working on v1 and it should support cjs/esm/browser in a much more modern (and working) way
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.
It is pretty close to done. I think by end of the week
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';
:rocket: Issue was released in v1.0.2 :rocket: