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

Integration with Angular 8 #654

Closed
cwilkens opened this issue Jan 22, 2020 · 6 comments · Fixed by #761
Closed

Integration with Angular 8 #654

cwilkens opened this issue Jan 22, 2020 · 6 comments · Fixed by #761

Comments

@cwilkens
Copy link

I'm fairly new to Angular so maybe I'm setting this up wrong, but I can't get pptxgenjs version 3.1.0 to work with Angular 8.3.0.

I made a plain Angular app using ng new app and then called npm install pptxgenjs to add it. When I run ng serve to build, I get a few errors like this:
ERROR in node_modules/pptxgenjs/types/index.d.ts:85:50 - error TS2591: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig.

So then I add node to the types field in tsconfig.app.json. Any way I try to build from there, or change the import/require of pptxgenjs in my angular component, I always get this build error:
ERROR in ./node_modules/pptxgenjs/dist/pptxgen.es.js Module not found: Error: Can't resolve 'fs' in 'C:\projects\slides-generator\node_modules\pptxgenjs\dist'

I looked at some other issues that have been closed, and maybe this is due to pptxgenjs thinking it's running on node instead of angular, but I don't know where that code is. (And I tried to put breakpoints in pptxgen.es.js everywhere I saw fs but they never got hit. Probably since the VS Code debugger was looking at runtime code instead of the compile process).

Any thoughts on how I can work around this or fix this?

gitbrent added a commit that referenced this issue Jan 24, 2020
@gitbrent
Copy link
Owner

Hi @cwilkens

Thanks for reporting this.

Angular is browser-based so fs should not be loading as a dependency. I'm guessing the "browser" field in package.json flags this. React built okay, so i assumed it was safe to remove during the last release (plus the spec shows it being used differently...)

Please download package.json from the master branch and replace the one in the node_modules/pptxgenjs folder, then try to build again and let me know.

@gitbrent gitbrent self-assigned this Jan 24, 2020
@gitbrent gitbrent added this to the 3.2.0 milestone Jan 24, 2020
@cwilkens
Copy link
Author

cwilkens commented Jan 24, 2020

Looking at my package.json, it seems it was munged/added to by npm. So I just added in the "browser" field from your recent change to the package.json file in node_modules/pptxgenjs, and it works.

For reference, I have to import it like so:
import PptxGenJS from 'pptxgenjs';

which gives a red squiggly in VS Code about index.d.ts(11, 1): This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
but I'm still able to ng serve and use the library normally:
var pptx = new PptxGenJS();
var slide = pptx.addSlide();

So I'm considering this fixed, thank you!

@gitbrent gitbrent modified the milestones: 3.2.0, 3.1.1 Jan 28, 2020
gitbrent added a commit that referenced this issue Jan 28, 2020
@readeral
Copy link

FWIW I was having trouble with fs in React using 3.1.0, but having installed from current master branch instead of NPM, that's no longer an issue.

@gitbrent
Copy link
Owner

@readeral - thanks for the feedback

@pandersen-uncharted
Copy link

I'm using 3.1.1 and still experiencing in an Angular 8 client-side app:

ERROR: node_modules/pptxgenjs/types/index.d.ts(67,50): error TS2591: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig.

I've tried adding node to the types field in tsconfig.app.json and that didn't work.

Instead I removed Buffer from lines 67 and 73 in node_modules/pptxgenjs/types/index.d.ts and that worked. Buffer is a node.js datatype so removing it from a non-node app makes sense, but doing this manually isn't maintainable. Is there an alternative solution?

ericrockey pushed a commit to WeTransfer/PptxGenJS that referenced this issue Mar 24, 2020
ericrockey pushed a commit to WeTransfer/PptxGenJS that referenced this issue Mar 24, 2020
ericrockey pushed a commit to WeTransfer/PptxGenJS that referenced this issue Mar 24, 2020
@zmzimpl
Copy link

zmzimpl commented Apr 13, 2020

The problem still exists in angular9

    node_modules/pptxgenjs/types/index.d.ts:73:88 - error TS2591: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig.
    
    73  write(outputType: PptxGenJS.JSZIP_OUTPUT_TYPE): Promise<string | ArrayBuffer | Blob | Buffer | Uint8Array>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants