gitbrent / PptxGenJS

Create PowerPoint presentations with a powerful, concise JavaScript API.
https://gitbrent.github.io/PptxGenJS/
MIT License
3.01k stars 645 forks source link

"Module not found: Error: Can't resolve" error in Angular 6 made worse by 2.3.0 #407

Closed antiremy closed 6 years ago

antiremy commented 6 years ago

So I updated PptxGenJS to 2.3.0, and actually ended up getting a much longer list of "Module not found: Error: Can't resolve" than I did with 2.2.0. No amount of messing with package.json files seemed to help.

It's worth noting that it's no longer fs or path, but crypto, http, https, and a few others. The full log is below


WARNING in ./node_modules/jsdom/lib/jsdom/utils.js
186:21-40 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/parse5/lib/index.js
55:23-49 Critical dependency: the request of a dependency is an expression

ERROR in ./node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js
Module not found: Error: Can't resolve 'child_process' in '/Users/abc123/Downloads/RRFE/node_modules/jsdom/lib/jsdom/living'
ERROR in ./node_modules/aws-sign2/index.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/aws-sign2'
ERROR in ./node_modules/aws4/aws4.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/aws4'
ERROR in ./node_modules/ecc-jsbn/index.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/ecc-jsbn'
ERROR in ./node_modules/http-signature/lib/verify.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/http-signature/lib'
ERROR in ./node_modules/http-signature/lib/signer.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/http-signature/lib'
ERROR in ./node_modules/oauth-sign/index.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/oauth-sign'
ERROR in ./node_modules/request/lib/helpers.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/request/lib'
ERROR in ./node_modules/request/lib/hawk.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/request/lib'
ERROR in ./node_modules/request/lib/oauth.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/request/lib'
ERROR in ./node_modules/sshpk/lib/utils.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/sshpk/lib'
ERROR in ./node_modules/sshpk/lib/private-key.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/sshpk/lib'
ERROR in ./node_modules/sshpk/lib/key.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/sshpk/lib'
ERROR in ./node_modules/sshpk/lib/fingerprint.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/sshpk/lib'
ERROR in ./node_modules/sshpk/lib/signature.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/sshpk/lib'
ERROR in ./node_modules/sshpk/lib/certificate.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/sshpk/lib'
ERROR in ./node_modules/sshpk/lib/identity.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/sshpk/lib'
ERROR in ./node_modules/sshpk/lib/dhe.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/sshpk/lib'
ERROR in ./node_modules/sshpk/lib/formats/openssh-cert.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/sshpk/lib/formats'
ERROR in ./node_modules/sshpk/lib/formats/pem.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/sshpk/lib/formats'
ERROR in ./node_modules/sshpk/lib/formats/ssh-private.js
Module not found: Error: Can't resolve 'crypto' in '/Users/abc123/Downloads/RRFE/node_modules/sshpk/lib/formats'
ERROR in ./node_modules/forever-agent/index.js
Module not found: Error: Can't resolve 'http' in '/Users/abc123/Downloads/RRFE/node_modules/forever-agent'
ERROR in ./node_modules/http-signature/lib/signer.js
Module not found: Error: Can't resolve 'http' in '/Users/abc123/Downloads/RRFE/node_modules/http-signature/lib'
ERROR in ./node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js
Module not found: Error: Can't resolve 'http' in '/Users/abc123/Downloads/RRFE/node_modules/jsdom/lib/jsdom/living'
ERROR in ./node_modules/request/request.js
Module not found: Error: Can't resolve 'http' in '/Users/abc123/Downloads/RRFE/node_modules/request'
ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'http' in '/Users/abc123/Downloads/RRFE/node_modules/tunnel-agent'
ERROR in ./node_modules/forever-agent/index.js
Module not found: Error: Can't resolve 'https' in '/Users/abc123/Downloads/RRFE/node_modules/forever-agent'
ERROR in ./node_modules/request/request.js
Module not found: Error: Can't resolve 'https' in '/Users/abc123/Downloads/RRFE/node_modules/request'
ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'https' in '/Users/abc123/Downloads/RRFE/node_modules/tunnel-agent'
ERROR in ./node_modules/forever-agent/index.js
Module not found: Error: Can't resolve 'net' in '/Users/abc123/Downloads/RRFE/node_modules/forever-agent'
ERROR in ./node_modules/tough-cookie/lib/cookie.js
Module not found: Error: Can't resolve 'net' in '/Users/abc123/Downloads/RRFE/node_modules/tough-cookie/lib'
ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'net' in '/Users/abc123/Downloads/RRFE/node_modules/tunnel-agent'
ERROR in ./node_modules/forever-agent/index.js
Module not found: Error: Can't resolve 'tls' in '/Users/abc123/Downloads/RRFE/node_modules/forever-agent'
ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'tls' in '/Users/abc123/Downloads/RRFE/node_modules/tunnel-agent'
ERROR in ./node_modules/request/request.js
Module not found: Error: Can't resolve 'zlib' in '/Users/abc123/Downloads/RRFE/node_modules/request'```
mrguodong commented 6 years ago

Have the same issue. If I add all of "Can't resolve" to browser part in package.json with false. Compile, however got Jquery not found in Chrome and unable to start application in broswer.

dgabriel commented 6 years ago

@gitbrent - I forked this project and haver a version of it that works super well with angular-cli and does not generate these errors.

Angular-cli 6 users can go to my updated README to see how to use it with their projects. https://github.com/dgabriel/PptxGenJS

I had to make a number of major changes, so I'm reluctant to issue a pull request. I'm delighted to explore it more if you want figure out how to incorporate in the main project. Here's what I had to change:

  1. Removed Node.Js dependancies from package.json
  2. Removed types.d file (caused 'not a module' error on ng serve)
  3. Removed ALL Node.js specific code from pptxgen.js and exported the module
  4. Updated package.json to reflect that this is a FORK and reset versioning
  5. ran npm pack

Your core project is AWESOME and I'm grateful for all the effort you put into it. This will end up saving me weeks of work.

gitbrent commented 6 years ago

@mrguodong - don't exclude jQuery, you'll need it (Node users require jsdom to enable jQuery to work).

@dgabriel - Yeah, excising a large chunk of the code isn't a solution for the project overall.

I'm continuing to work towards an integration method that works easier.

antiremy commented 6 years ago

@gitbrent so does this mean we shouldn't expect to get 2.3.0 working in angular?

I wouldn't mind working on a PR, I just don't really know whats causing the issue

gitbrent commented 6 years ago

It should work in Angular et al.

I'm unsure why there are more now than before... I don't use the library in Angular/React, so i'm not very proficient with integration.

Any and all help from experts in this area is very welcome.

antiremy commented 6 years ago

So after a bit of digging, I've narrowed the problem down to the code block inside the last if ( NODEJS ) on line 5216

Regardless of if NODEJS is true or false, that code is still trying to be compiled by Angular-CLI. It wouldn't be an issue, but the introduction of JSDOM has made it very Node specific. I could successfully get a PowerPoint created if I knocked the code in there down to just

if ( NODEJS ) {
    $ = require("jquery");
    try { JSZip = require("jszip"); } catch(ex){ console.error("Unable to load `jszip`"); throw 'LIB-MISSING-JSZIP'; }
    module.exports = PptxGenJS;
}

@gitbrent I also noticed that Node detection wasn't working well. When I was logging the output of typeof module and the other checks you use, they were coming back with what you'd expect for Node (module was not undefined and typeof require was a function). I'd suggest just changing the check to typeof window === 'undefined'

antiremy commented 6 years ago

@gitbrent Pretty sure I've got a fix, I'll make a PR this weekend

NashidB commented 6 years ago

@gitbrent Pretty sure I've got a fix, I'll make a PR this weekend

Definitely waiting on this, we were looking at using an earlier version since 2.3 is impossible to work with. I will check back on this Monday. Thanks.

antiremy commented 6 years ago

@Nashid95 PR has been posted, but give this a shot in the meantime https://github.com/antiremy/PptxGenJS

NashidB commented 6 years ago

@antiremy This works great, Thank you.

gitbrent commented 6 years ago

This issue should be resolved now with Issue #415 being checked in.

gitbrent commented 6 years ago

NOTE: 2.4.0 has been released and includes all code fixes that should address this issue.

gitbrent commented 6 years ago

Any updated feedback on this? @Nashid95 @antiremy @dgabriel

Have the integration issues been resolved for you guys with the newest release, 2.4.0?