When mac m1 runs with canvas module, the required arm64 architecture and system x86_64" do not match

To change the "canvas" module to support the "x86_64" architecture, you can try the following steps:

  1. Make sure you have installed all dependencies of the module "canvas". You can run the following command:

    npm install canvas
    
  2. Confirm whether the CMake tool is installed on your computer. If not, install it. On macOS, you can use Homebrew to execute the following commands:

    brew install cmake
    
  3. Make sure you have the Cairo and Pango libraries installed on your computer. On macOS, you can use Homebrew to install them:

    brew install pkg-config cairo pango libpng jpeg giflib
    
  4. Open a command line terminal and enter the directory of the "canvas" module.

    cd node_modules/canvas
    
  5. Execute the following command to edit the binding.gyp file of the "canvas" module:

    nano binding.gyp
    
  6. Find the "cflags" and "ldflags" sections in the binding.gyp file and change them to:

    "cflags": [ "-mmacosx-version-min=10.9" ],
    "ldflags": [ "-mmacosx-version-min=10.9" ],
    

    This will force Node.js to compile the "canvas" module using the "x86_64" architecture.

  7. Save and close the binding.gyp file.

  8. In the directory of the "canvas" module, execute the following command to rebuild the module:

    npm rebuild canvas
    
  9. Check if the "canvas" module has been successfully changed to support the "x86_64" architecture.

Guess you like

Origin blog.csdn.net/HU_YEWEN/article/details/131324243