-
Notifications
You must be signed in to change notification settings - Fork 647
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
Can't create multiple presentations in node #83
Comments
That would be nice, having the same issue here.
|
Hi @daynedavis @gerbendekker , Thanks for the question. I've added a new section to the README that covers this very issue: See also: Issue #38 |
How does this cover the NodeJs usecase of above? var pptx = require("pptxgenjs"); |
@gitbrent like @gerbendekker said I'm not able use new in NodeJs since the class is not exposed. |
Ack! I spaced out and used the wrong code. Sorry about that. It should've been Does this work for you guys, or would a more formal method like |
Now we are back where we started. Problem let pptx = require('pptxgenjs');
let slide1 = pptx.addNewSlide();
let slide2 = pptx.addNewSlide();
pptx = require('pptxgenjs');
// How many slides does pptx have? The answer is 2, because Solution module.exports = PptxGenJS; Then we can write: let PptxGenJS = require('pptxgenjs');
let pptx = new PptxGenJS();
let slide1 = pptx.addNewSlide();
let slide2 = pptx.addNewSlide();
pptx = new PptxGenJS();
// Yeay a new instance. But that is a breaking change. Thinking forward... |
I fixed it in the current version by deleting the module from the cache before requiring again: delete require.cache[require.resolve('pptxgenjs')]
let pptx = require('pptxgenjs') |
Here is a much cleaner work around: var pptxgenjs = require('pptxgenjs'); const pptx2 = new pptxgenjs.constructor(); Using the constructor property of the function will let you build new objects at will. |
Any news guys? |
Hi @dtabolich, Other than the newer posts above, no. The factory method will be updated in 2.0 as it's a breaking change, until then work-arounds are all that's available. :-( |
@gitbrent let me know your thoughts on this. It's not ideal but it would solve the issue in a way that node users should expect and keep things compatible. |
…n additional property is exposed for use with the new operator
Hi All, UPDATE: A fix for this issue is now checked into the 2.0.0 codebase! Individual, singleton instances of PptxGenJS are now created using the standard Node syntax: var PptxGenJS = require("pptxgenjs");
let pptx = new PptxGenJS(); If any of you would care to demo it and provide feedback, i'd appreciate it. :-) New Node Examples:
See README section for more: |
Version 2.0.0 has been released and this issue is now fixed. Thank you all for your feedback. |
I am requiring pptx via var pptx = require('pptxgenjs') within a function called by a route on my node server, but when I hit the endpoint multiple times slides are added to the same presentation (first time it returns a ppt with 4 slides, second time one with 8 slides). Changing module.exports to be PptxGenJs in pptxgen.js and then requiring pptx = new (require('pptxgenjs'))() allowed me to get separate instances. Is this a bug or is there a way to get multiple instances in node without making that change?
The text was updated successfully, but these errors were encountered: