-
Notifications
You must be signed in to change notification settings - Fork 141
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
Browser compatibility without Node shims #105
Comments
Hi, thanks for taking the effort of creating an example repo demonstrating the issue. Though, I'll need some days to find time to look into it in more detail. The error points at the following line: What Node version are you using? What do you get when executing % node
> require('stream').Readable
{ [Function: Readable] |
This is what I get but I don't believe it gets us anywhere cause my execution environment is the browser and not NodeJS (though node is used to transpile typescript -> javascript). But I'm a Java/Python backend guy doing Angular - I'm totally lacking background knowledge on the inner workings of these Javascript environment (I don't even know what
|
What seems to be related or a possible root cause is the fact that Angular 6 removed the NodeJS shims. |
Yes, this might be the cause. The browser support currently has the assumption that during transpiling/bundling of pdfjs, shims for the Node's stream interface are automatically inserted. Maybe, instead of relying on Node shims, |
The issue might be solves with current |
The problem is gone, but I got new problems: I don't believe going down this route (workarounds) leads to success I fear pdfjs needs dedicated support for the browser. This posting here seems to show a nice way: https://nolanlawson.com/2017/01/09/how-to-write-a-javascript-package-for-both-node-and-the-browser/ For the moment I leave my PDF generation on in the node environment even though I'd like to move it to the browser. (Sorry - can't spend too much time on it until my customer requests to move the PDF generation to the client.) |
Yeah, those are all parts that traditionally worked fine, since shims are automatically added during transpilation. I still have no issues running pdfjs in the browser, but I respect the use-case of disabling Node shims and are open to support it. I also agree that going with workarounds shouldn't be the long-term solution. Though, since it still works for my own usage, it might take some time until I find time to have a look of how to replace this stuff. Still, thanks for elaborating and reporting the issues that occurred. |
I also had this problem. Tried using the library in my Vite project and getting "global is not defined" error. |
I'm trying to make pdfjs work in Angular 6 (Angular 4 worked without any issue)
The code in https://github.com/sannies/pdfjs-angular6-issue compiles just fine but during runtime I get this error
document.js:17 Uncaught TypeError: Class extends value undefined is not a constructor or null at Object../node_modules/pdfjs/lib/document.js (document.js:17) at __webpack_require__ (bootstrap:76) at Object../node_modules/pdfjs/lib/index.js (index.js:5) at __webpack_require__ (bootstrap:76) at Object../src/app/pdf-generator.service.ts (app.module.ts:17) at __webpack_require__ (bootstrap:76) at Object../src/app/app.component.ts (main.js:94) at __webpack_require__ (bootstrap:76) at Object../src/app/app.module.ts (app.component.ts:10) at __webpack_require__ (bootstrap:76)
would you be able to point me in the right direction?
The text was updated successfully, but these errors were encountered: