mac M1 failed to install node-canvas

Failed to execute '/Users/.nvm/versions/node/v14.20.0/bin/node /Users/.nvm/versions/node/v14.20.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --update-binary --module=/Users/qsk/Projects/arms-inspections/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/Users/Projects/arms-inspections/node_modules/canvas/build/Release --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v83' (1)

This error seems to be caused by a failure during the compilation and installation of the node-canvas module.

Here are the possible causes and solutions for this issue:

  1. Missing dependencies - A dependency required by the node-canvas module might not be installed or not installed correctly. On macOS, Cairo and Pango need to be installed. You can install these dependencies using the following command:

    brew install pkg-config cairo pango libpng jpeg giflib
    

    If you are using another operating system, please install the corresponding dependent libraries according to the operating system and target package manager. After installing the dependencies, try reinstalling node-canvas.

  2. Compatibility issue - node-canvas is not compatible with the current Node.js/npm version. Try installing node-canvas using an older or newer Node.js/npm version. You can upgrade or downgrade the Node.js version and then reinstall the package. If you use nvm to manage Node.js versions, you can use the following command to install the required Node.js version:

    nvm install <版本号>
    
  3. Compilation or installation problems - This may be caused by compilation or installation errors. You can first try removing the node-canvas module and reinstalling it:

    npm uninstall canvas
    npm install canvas
    
  4. Other issues - If none of the above methods help you resolve the issue, you may need to dig deeper into the error and troubleshoot based on the error message.

Guess you like

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