pixiedust icon indicating copy to clipboard operation
pixiedust copied to clipboard

canvas package not working in docker with turbo

Open jordan-loeser opened this issue 1 year ago • 0 comments

When implementing a pruned and optimized Dockerfile using turbo, I'm getting the following error on docker run:

$ docker run -p 3000:3000 pixiedust
Error: Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package)
    at module.exports (/app/node_modules/jsdom/lib/jsdom/browser/not-implemented.js:9:17)
    at HTMLCanvasElementImpl.getContext (/app/node_modules/jsdom/lib/jsdom/living/nodes/HTMLCanvasElement-impl.js:42:5)
    at HTMLCanvasElement.getContext (/app/node_modules/jsdom/lib/jsdom/living/generated/HTMLCanvasElement.js:131:58)
    at new Applet (/app/packages/pixiedust/classes/Applet.js:24:32)
    at new NYCTrainApplet (/app/pixiedust-applets/nyctrainsign/index.js:23:9)
    at Object.<anonymous> (/app/apps/renderer/dist/index.js:74:20)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12) undefined
/app/packages/pixiedust/classes/Applet.js:26
            throw new Error("Could not get canvas context.");
            ^

Error: Could not get canvas context.
    at new Applet (/app/packages/pixiedust/classes/Applet.js:26:19)
    at new NYCTrainApplet (/app/pixiedust-applets/nyctrainsign/index.js:23:9)
    at Object.<anonymous> (/app/apps/renderer/dist/index.js:74:20)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.17.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

When I consolidate the Dockerfile into 1 build stage and remove turbo pruning, it works. It looks like some of the canvas dependency, which must be built natively, isn't getting copied correctly during one of the stages, because I ran into this issue early on even without using turbo.

Dockerfile in question here: https://github.com/Jordan-Loeser/pixiedust-express/blob/fd5732f9d05931033103913ab737b771261cc528/Dockerfile

jordan-loeser avatar Dec 24 '23 07:12 jordan-loeser