jimp-dev / jimp

An image processing library written entirely in JavaScript for Node, with zero external or native dependencies.
http://jimp-dev.github.io/jimp/
MIT License
14.01k stars 760 forks source link

Jimp breaks Bluebird - PromisifyAll is not a function #674

Closed ananaszjoe closed 1 year ago

ananaszjoe commented 5 years ago

Expected Behavior

Jimp should not break other modules

Current Behavior

I use Bluebird and Raven like so:

global.Promise = require('bluebird')
const raven = global.Promise.promisifyAll(require('raven'))

if I require Jimp in my project like so, var Jimp = require('jimp') It breaks Bluebird's pormisifyAll function and I get the following error: TypeError: global.Promise.promisifyAll is not a function

When I only remove var Jimp = require('jimp') from my poject, it runs without problem.

Steps to Reproduce

  1. Include and use Bluebird and Raven like so (app.js):

    global.Promise = require('bluebird')
    const raven = global.Promise.promisifyAll(require('raven'))
  2. Include Jimp in the project (for me it's in a separate file for a controller): var Jimp = require('jimp')

  3. run $ node app

Context

Failure Logs

> npm run start

> oa-api@0.1.0 start <redacted>
> node app

WARN: `increment` should not be used as a schema path name unless you have disabled versioning.
C:\<redacted>\app.js:12
const raven = global.Promise.promisifyAll(require('raven')) // Sentry.io
                             ^

TypeError: global.Promise.promisifyAll is not a function
    at Object.<anonymous> (C:\<redacted>\app.js:12:30)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! oa-api@0.1.0 start: `node app`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the oa-api@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\<redacted>\AppData\Roaming\npm-cache\_logs\2018-12-08T13_32_44_404Z-debug.log
hipstersmoothie commented 5 years ago

That's weird as hell. Will def look into this this week

Jakovb commented 5 years ago

Can confirm, any eta?

oliversalzburg commented 5 years ago

https://github.com/feathersjs/feathers/issues/510

Using global is not a great idea.

hipstersmoothie commented 5 years ago

Sorry i didn't get around to this. On vacation for the holidays so I'm having trouble getting around to this PRs are always welcome :)

oliversalzburg commented 5 years ago

@hipstersmoothie I was suggesting that babel-polyfill clobbers global.Promise. I don't understand why they do that if a symbol exists at that location, but it'd be an issue with babel-polyfill in that case.

In general, I would recommend to not use global in user code. If you want bluebird, just const Promise = require("bluebird"); everywhere where you want to use it.

That being said, the actual on-disk modules that are produced by jimp are a horror to debug and I don't think a babel-polyfill should be loaded by a dependency in a NodeJS project...

hipstersmoothie commented 5 years ago

Awesome findings! What would you suggest doing instead of babel polyfill to support old versions of node?

Also how are they a horror to debug? I'm interested in filing issues for this is you can provide examples.

PRs welcome ❤️

(I agree that using global like this is probably not the best idea @ananaszjoe is this the suggested way of using bluebird? I have never used it)

oliversalzburg commented 5 years ago

What would you suggest doing instead of babel polyfill to support old versions of node?

Don't support old versions. If the consumer of the library wants to use it with an older version of Node, have them include a polyfill where it makes sense for them.

Also how are they a horror to debug?

When I set a breakpoint on the require("jimp") call and step into the module code, I find it very hard to follow. Especially if your goal is to find out where something might register a symbol on global. But that might just be me. I just don't like debugging transpiled code. And I only got into this issue randomly. I'm not even affected by it. So I guess we can ignore my personal preference here.

github-actions[bot] commented 1 year ago

:rocket: Issue was released in v0.21.0 :rocket: