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

TypeError: Cannot redefine property: saveJpeg #84

Open
scheepers opened this issue Sep 11, 2020 · 3 comments
Open

TypeError: Cannot redefine property: saveJpeg #84

scheepers opened this issue Sep 11, 2020 · 3 comments

Comments

@scheepers
Copy link

When running test suites that include async test cases for modules using:

gd = require ('node-gd')

The following error occurs:

    TypeError: Cannot redefine property: saveJpeg
        at Function.defineProperty (<anonymous>)

       7 | 
       8 | 
    >  9 | const gd =  require('node-gd')
         |             ^
      10 | 
      11 | 
      12 | class Tile {

      at node_modules/node-gd/lib/node-gd.js:89:12
          at Array.forEach (<anonymous>)
      at Object.<anonymous> (node_modules/node-gd/lib/node-gd.js:82:9)
      at Object.<anonymous> (node_modules/node-gd/index.js:10:18) 

Which can be fixed by this patch:

--- lib/node-gd.js	2020-09-11 21:24:59.945903226 +0200
+++ lib/node-gd-new.js	2020-09-11 21:44:00.075234552 +0200
@@ -85,10 +85,11 @@
     return;
   }
 
-  if (!`save${format}`) Object.defineProperty(
-    bindings.Image.prototype, `save${format}`, {
-    value: saveFormatFn(format)
-  });
+  if (!bindings.Image.prototype[`save${format}`]){
+    Object.defineProperty(bindings.Image.prototype, `save${format}`, {
+      value: saveFormatFn(format)
+    });
+  }
 });
 
 /**
@y-a-v-a
Copy link
Owner

y-a-v-a commented Sep 13, 2020

HI @scheepers thanks for reaching out. Could you elaborate on test suites that use async test cases? What does your code setup look like in those cases?
I'm wondering if your proposed solution is enough, in the sense that either we would need to make a "deeper" fix, or you might need to change the way you load node-gd. Could you supply a test case in order to investigate it more thorough? Thanks in advance.
Regards, Vincent

@scheepers
Copy link
Author

scheepers commented Sep 13, 2020

Hi Vince, thanks for responding.
My test cases are written in Jest for the following use case: an image wrapper to encapsulate image loading and a few calculation functions. Many of those are contained in a dictionary loaded from a directory of images.
I've now found if I run the test suites for these two objects seperately they both pass all tests, but running the whole suite produces the error result.

@maximshe
Copy link

maximshe commented Dec 17, 2021

Hi @y-a-v-a , I noticed the same behavior. My case is close to the one above.

maximshe added a commit to maximshe/node-gd that referenced this issue Dec 20, 2021
maximshe added a commit to maximshe/node-gd that referenced this issue Dec 20, 2021
See y-a-v-a#84

(cherry picked from commit df75957)
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

No branches or pull requests

3 participants