Canvas doesn't seem to be working
Environment
NodeJS v22
Reproduction
const image = await renderPageAsImage(pdf, i, {
width: 1700,
canvas: () => import("canvas"),
});
Describe the bug
Error processing PDF: TypeError: _canvas.createCanvas is not a function
at Object._createCanvas (webpack-internal:///(rsc)/./node_modules/unpdf/dist/index.mjs:125:24)
at Object.create (webpack-internal:///(rsc)/./node_modules/unpdf/dist/index.mjs:130:29)
at renderPageAsImage$1 (webpack-internal:///(rsc)/./node_modules/unpdf/dist/index.mjs:102:29)
Additional context
No response
Logs
No response
I have the same issue
Huh, that's weird. I will have to investigate.
Any update on this issue ? I have the same issue using Node.js 20 environment
I don't have the resource to work on this at the moment. A quick solution didn't seem in reach when I debugged it. PR welcome!
I am able to fix this issue, so my problem was I used in Azure Devops different kind of agent pool to build my module, because I updated the pdfjs-dist version 2.15.349 NPM package to use unpdf version 0.12.1, and in the meantime I updated the node version as well from 18.18.0 to 20.18.0, and during this update there were many breaking change between the different versions, but I could handle it well.
So I used ubuntu:22.04 agent and node.js 18.18.0 accidentally to build my node.js module, and I run my integration test on a different ci docker agent pool, which is used node.js 20.18.0, and I got the same error what is mentioned above. So I fixed this little mistake and now everything works fine.
Currently I used this NPM install command:
npm ci --arch=x64 --platform=win32 --target_arch=x64 --target_platform=win32 --target_libc=unknown
My NPM dependencies currently:
"canvas": "2.11.2
"unpdf": "0.12.1",
Should be fixed in https://github.com/unjs/unpdf/commit/199e2ee9d7ab15ff371b6e4e8fce73fad4b5c318.