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

Unable to get it working in a Vue project. #1283

Open
Marchiuzzz opened this issue Mar 13, 2024 · 3 comments · May be fixed by #1285
Open

Unable to get it working in a Vue project. #1283

Marchiuzzz opened this issue Mar 13, 2024 · 3 comments · May be fixed by #1285

Comments

@Marchiuzzz
Copy link

Expected Behavior

Following the docs, I should be able to use Jimp out of the box

Current Behavior

I get a TypeError: Jimp is not a constructor or TypeError: jimp__WEBPACK_IMPORTED_MODULE_1___default(...) is not a constructor error.

Context

When importing Jimp like this:
import Jimp from "jimp"
I get TypeError: jimp__WEBPACK_IMPORTED_MODULE_1___default(...) is not a constructor error

I have also tried using it like so var Jimp = require("jimp") but then I get TypeError: Jimp is not a constructor

This is the full code

import _ from "lodash"
import Jimp from "jimp"

class ImageMaker {
	static make_money_img(coins, height) {
		// var Jimp = require("jimp")  <---- tried this as well 
		let coinwidth = 100
		let coinheight = coinwidth * 0.55
		let coincount = coins.length
		let matrix_width = Math.ceil(coincount / height)
		let x = matrix_width
		let y = height

		let img_w = coinwidth * x
		let img_h = coinheight * y

		var mainImage = new Jimp(img_w, img_h, 0x0, (err, image) => {
			// ... my code here
		})
		return mainImage.getBase64(Jimp.MIME_PNG)
	}
}

export { ImageMaker }

  • Jimp Version: ^0.22.12
  • Operating System: Windows 11
  • Node version: v14.21.3

Failure Logs

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

Same issue, any luck?

@Marchiuzzz
Copy link
Author

@supersuryaansh Yeah, I managed to get it working using

import "jimp"
const { Jimp } = window

@supersuryaansh
Copy link

@Marchiuzzz thanks, I got it working with this:
import * as _Jimp from 'jimp';
const Jimp = (typeof self !== 'undefined') ? (self.Jimp || _Jimp) : _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.

2 participants