openedx/frontend-lib-content-components

Cannot build on arm64 because of "canvas" requirement

Closed this issue · 6 comments

I'm having trouble starting my Tutor Nightly devstack on an ARM64 MacBook, because when it tries to build the course-authoring MFE, it tries to install this package's canvas dependency, but canvas doesn't provide arm64 builds and the Tutor docker environment isn't set up to compile binaries using node-gyp.

So the failure is:

 > [course-authoring-common 3/5] RUN npm clean-install --no-audit --no-fund --registry=https://registry.npmjs.org/   && rm -rf ~/.npm:
...
#60 89.56 npm ERR! node-pre-gyp ERR! install response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.10.1/canvas-v2.10.1-node-v93-linux-glibc-arm64.tar.gz 
#60 89.56 npm ERR! node-pre-gyp WARN Pre-built binaries not installable for canvas@2.10.1 and node@16.14.2 (node-v93 ABI, glibc) (falling back to source compile with node-gyp)
...
#60 89.56 npm ERR! gyp ERR! stack Error: Could not find any Python installation to use
#60 89.56 npm ERR! node-pre-gyp ERR! build error

However, should canvas even be listed as a dependency in the first place? I could not see any usage of it in the code from a quick look, so I assume it's only being used to polyfill the Canvas API for the test suite, though I couldn't see even that in the PR either. But if it is required for the tests, it should be in devDependencies, not dependencies, right?

Attn: @KristinAoki

@bradenmacdonald I imagine that this would break for anyone running npm ci on ARM64, regardless of whether they use Tutor, right?

@kdmccormick Not necessarily; for example it would probably work on your host if you have a valid development environment. The problem is that in the MFE container build environment that Tutor uses, python3 is not installed (and probably other header files and compilers that may be needed to build) so it cannot fall back to compiling canvas from scratch.

Yes, I installed it for tests. I don't import in the tests, but is needed so the test can create the canvas because Jest doesn't have the capability. I agree that it should be moved from dependencies to devDependencies.

Cool, I think that devDependencies is better, but I don't think it will solve the tutor build issue, because tutor-mfe needs to install the devDependencies to build the MFE anyways. It doesn't actually need canvas installed to build or run the MFE though, so one option would be a hack to comment out that dependency when building in tutor on arm64.

Some proper solutions could be:

  • Use a tutor build environment that is able to compile canvas
  • Use an alternate Canvas implementation that doesn't require a platform-specific binary, e.g. use a wasm-based Canvas implementation.
  • Somehow separate the test dependencies so it's only installed if/when running npm test.
  • Get upstream to publish an arm64 build - seems unlikely as there are tons of arm64 build issues reported and the request for an ARM build has been ignored for three years.

Does anyone know if this is still an issue?

@kdmccormick I haven't seen this issue at all, and it looks like jest-canvas-mock is now listed as a dependency instead of canvas. So I'm going to close this.