I am using Angular standalone component (no modules) with Angular Universal (Express Engine). I added ng2-pdf-viewer but when I start the server, I am getting the below error:
./node_modules/canvas/build/Release/canvas.node:1:0 - Error: Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
You can mark the path "canvas" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle. You can also surround this "require" call with a try/catch block to handle this failure at run-time instead of bundle-time.
Clearly it is something with canvas. Not sure how to fix this. Any thoughts?
I am using Angular standalone component (no modules) with Angular Universal (Express Engine). I added ng2-pdf-viewer but when I start the server, I am getting the below error:
./node_modules/canvas/build/Release/canvas.node:1:0 - Error: Module parse failed: Unexpected character '�' (1:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders (Source code omitted for this binary file)
My package.json is as below:
When I started the server with ng serve, it works fine. The issue I think is with dev:ssr (or with universal only)
Tested it with Angular 17.0.0 (standalone + Angular SSR this time) as well as below:
The error is more clear there:
node_modules/pdfjs-dist/build/pdf.js:8671:35: 8671 │ const Canvas = require("canvas"); ╵
~~~~You can mark the path "canvas" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle. You can also surround this "require" call with a try/catch block to handle this failure at run-time instead of bundle-time.
Clearly it is something with canvas. Not sure how to fix this. Any thoughts?