Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm intall not working #2371

Closed
ArtichautDev opened this issue Mar 31, 2024 · 10 comments
Closed

npm intall not working #2371

ArtichautDev opened this issue Mar 31, 2024 · 10 comments

Comments

@ArtichautDev
Copy link

ArtichautDev commented Mar 31, 2024

Issue or Feature

  • [ yes] If this is an issue with installation, I have read the troubleshooting guide.
    I can't install canvas on my Mac, I have this error:
    artichaut@Pierres-MacBook-Air-3820 SpotiPixel % sudo npm i canvas
    npm ERR! code 1
    npm ERR! path /Users/artichaut/Documents/GitHub/SpotiPixel/node_modules/canvas
    npm ERR! command failed
    npm ERR! command sh -c node-pre-gyp install --fallback-to-build --update-binary
    npm ERR! Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --update-binary --module=/Users/artichaut/Documents/GitHub/SpotiPixel/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/Users/artichaut/Documents/GitHub/SpotiPixel/node_modules/canvas/build/Release --napi_version=9 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v108' (1)
    npm ERR! node-pre-gyp info it worked if it ends with ok
    npm ERR! node-pre-gyp info using node-pre-gyp@1.0.11
    npm ERR! node-pre-gyp info using node@18.18.0 | darwin | arm64
    npm ERR! node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-node-v108-darwin-unknown-arm64.tar.gz
    npm ERR! node-pre-gyp ERR! install response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-node-v108-darwin-unknown-arm64.tar.gz
    npm ERR! node-pre-gyp WARN Pre-built binaries not installable for canvas@2.11.2 and node@18.18.0 (node-v108 ABI, unknown) (falling back to source compile with node-gyp)
    npm ERR! node-pre-gyp WARN Hit error response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-node-v108-darwin-unknown-arm64.tar.gz
    npm ERR! gyp info it worked if it ends with ok
    npm ERR! gyp info using node-gyp@9.4.0
    npm ERR! gyp info using node@18.18.0 | darwin | arm64
    npm ERR! gyp info ok
    npm ERR! gyp info it worked if it ends with ok
    npm ERR! gyp info using node-gyp@9.4.0
    npm ERR! gyp info using node@18.18.0 | darwin | arm64
    npm ERR! gyp info find Python using Python version 3.12.2 found at "/usr/local/opt/python@3.12/bin/python3.12"
    npm ERR! gyp info spawn /usr/local/opt/python@3.12/bin/python3.12
    npm ERR! gyp info spawn args [
    npm ERR! gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
    npm ERR! gyp info spawn args 'binding.gyp',
    npm ERR! gyp info spawn args '-f',
    npm ERR! gyp info spawn args 'make',
    npm ERR! gyp info spawn args '-I',
    npm ERR! gyp info spawn args '/Users/artichaut/Documents/GitHub/SpotiPixel/node_modules/canvas/build/config.gypi',
    npm ERR! gyp info spawn args '-I',
    npm ERR! gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
    npm ERR! gyp info spawn args '-I',
    npm ERR! gyp info spawn args '/Users/artichaut/Library/Caches/node-gyp/18.18.0/include/node/common.gypi',
    npm ERR! gyp info spawn args '-Dlibrary=shared_library',
    npm ERR! gyp info spawn args '-Dvisibility=default',
    npm ERR! gyp info spawn args '-Dnode_root_dir=/Users/artichaut/Library/Caches/node-gyp/18.18.0',
    npm ERR! gyp info spawn args '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
    npm ERR! gyp info spawn args '-Dnode_lib_file=/Users/artichaut/Library/Caches/node-gyp/18.18.0/<(target_arch)/node.lib',
    npm ERR! gyp info spawn args '-Dmodule_root_dir=/Users/artichaut/Documents/GitHub/SpotiPixel/node_modules/canvas',
    npm ERR! gyp info spawn args '-Dnode_engine=v8',
    npm ERR! gyp info spawn args '--depth=.',
    npm ERR! gyp info spawn args '--no-parallel',
    npm ERR! gyp info spawn args '--generator-output',
    npm ERR! gyp info spawn args 'build',
    npm ERR! gyp info spawn args '-Goutput_dir=.'
    npm ERR! gyp info spawn args ]
    npm ERR! Traceback (most recent call last):
    npm ERR! File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 42, in
    npm ERR! import gyp # noqa: E402
    npm ERR! ^^^^^^^^^^
    npm ERR! File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/init.py", line 9, in
    npm ERR! import gyp.input
    npm ERR! File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 19, in
    npm ERR! from distutils.version import StrictVersion
    npm ERR! ModuleNotFoundError: No module named 'distutils'
    npm ERR! gyp ERR! configure error
    npm ERR! gyp ERR! stack Error: gyp failed with exit code: 1
    npm ERR! gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:325:16)
    npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:517:28)
    npm ERR! gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:292:12)
    npm ERR! gyp ERR! System Darwin 23.2.0
    npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--update-binary" "--module=/Users/artichaut/Documents/GitHub/SpotiPixel/node_modules/canvas/build/Release/canvas.node" "--module_name=canvas" "--module_path=/Users/artichaut/Documents/GitHub/SpotiPixel/node_modules/canvas/build/Release" "--napi_version=9" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v108"
    npm ERR! gyp ERR! cwd /Users/artichaut/Documents/GitHub/SpotiPixel/node_modules/canvas
    npm ERR! gyp ERR! node -v v18.18.0
    npm ERR! gyp ERR! node-gyp -v v9.4.0
    npm ERR! gyp ERR! not ok
    npm ERR! node-pre-gyp ERR! build error
    npm ERR! node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --update-binary --module=/Users/artichaut/Documents/GitHub/SpotiPixel/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/Users/artichaut/Documents/GitHub/SpotiPixel/node_modules/canvas/build/Release --napi_version=9 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v108' (1)
    npm ERR! node-pre-gyp ERR! stack at ChildProcess. (/Users/artichaut/Documents/GitHub/SpotiPixel/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
    npm ERR! node-pre-gyp ERR! stack at ChildProcess.emit (node:events:517:28)
    npm ERR! node-pre-gyp ERR! stack at maybeClose (node:internal/child_process:1098:16)
    npm ERR! node-pre-gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:303:5)
    npm ERR! node-pre-gyp ERR! System Darwin 23.2.0
    npm ERR! node-pre-gyp ERR! command "/usr/local/bin/node" "/Users/artichaut/Documents/GitHub/SpotiPixel/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build" "--update-binary"
    npm ERR! node-pre-gyp ERR! cwd /Users/artichaut/Documents/GitHub/SpotiPixel/node_modules/canvas
    npm ERR! node-pre-gyp ERR! node -v v18.18.0
    npm ERR! node-pre-gyp ERR! node-pre-gyp -v v1.0.11
    npm ERR! node-pre-gyp ERR! not ok

npm ERR! A complete log of this run can be found in: /Users/artichaut/.npm/_logs/2024-03-31T19_47_54_510Z-debug-0.log

(already tried this https://github.com/Automattic/node-canvas/wiki/Installation%3A-Mac-OS-X)
and this https://stackoverflow.com/questions/71352368/is-it-possible-to-install-canvas-with-m1-chip )

Steps to Reproduce

npm I canvas

Your Environment

  • Version of node-canvas (output of npm list canvas or yarn list canvas): none
  • Environment (e.g. node 20.9.0 on macOS 14.1.1):
    node v18.18.0 on Mac OS Sonoma 14.2.1 m2 MacBook Air
@ArtichautDev ArtichautDev changed the title nom i npm intall not working Mar 31, 2024
@nnmbzr
Copy link

nnmbzr commented Apr 1, 2024

You have error in log:

ModuleNotFoundError: No module named 'distutils'

Try install setuptools

brew install python-setuptools

@ArtichautDev
Copy link
Author

yes thank you its working, but now I have this error:
node:internal/modules/cjs/loader:1340
return process.dlopen(module, path.toNamespacedPath(filename));
^

Error: dlopen(/Users/artichaut/Documents/GitHub/2/SpotiPixel/node_modules/canvas/build/Release/canvas.node, 0x0001): symbol not found in flat namespace '_cairo_fill'

I already tried brew install cairo

@nnmbzr
Copy link

nnmbzr commented Apr 2, 2024

Okay, maybe you need to install all of this?

brew install pkg-config cairo pango libpng jpeg giflib librsvg

@Hamfri
Copy link

Hamfri commented Apr 2, 2024

If you are on a recent version of Mac OS the default python version is 3.x.x. For unknown reasons canvas could not be compiled if python version was 3.x.x. Run the following commands:-

  1. $ brew install pkg-config cairo pango libpng jpeg giflib librsvg

  2. $ brew install pyenv

  3. $ pyenv install 2.7.18

  4. $ brew install python-setuptools

  5. Set the following environment variables in your .zshrc or .bashrc depending on your default shell.

    export PATH=$(pyenv root)/shims:$PATH
    export PATH="$(pyenv root)/versions/2.7.18/bin:$PATH"
    
  6. $ source ~/.zshrc or ~/.bashrc depending on your default shell.

  7. $ npm config set python python2.7

  8. $ if on an existing project run $ rm -rf node_module && npm i.

  9. For fresh installs run $ npm i canvas

Note: I used this solution on MacBook pro M1 macOS Sonoma 14.4.1

@cmahnke
Copy link

cmahnke commented Apr 2, 2024

Just in case anyone else has this problem on a recent Mac OS: There has been an (brew) update for pango (I guess).
You should also observe Package glib-2.0 was not found in the pkg-config search path. during building.

First, check if pkgconfig find the required dependencies: pkg-config pangocairo --libs
Make sure you get the following result:

-L/opt/homebrew/Cellar/pango/1.52.2/lib -L/opt/homebrew/Cellar/glib/2.80.0_2/lib -L/opt/homebrew/opt/gettext/lib -L/opt/homebrew/Cellar/harfbuzz/8.4.0/lib -L/opt/homebrew/Cellar/cairo/1.18.0/lib -lpangocairo-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lintl -lharfbuzz -lcairo

This is an error:

Package gobject-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gobject-2.0.pc'
to the PKG_CONFIG_PATH environment variable
Package 'gobject-2.0', required by 'pango', not found

If you get an error reinstall glib using brew: brew reinstall glib

@nnmbzr
Copy link

nnmbzr commented Apr 2, 2024

If you are on a recent version of Mac OS the default python version is 3.x.x. For unknown reasons canvas could not be compiled if python version was 3.x.x.

In my case, it compiled* on python 3.12.2

* after many painful hours

@cmahnke
Copy link

cmahnke commented Apr 2, 2024

Yes, I forgot to mention it: Python 3.1X is expected to work

@TrevorSayre
Copy link

This is my current process for a failed install on Apple Silicon:

brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman python@3.12
rm -rf node_modules
npm install

If you don't have the brew command from homebrew: https://brew.sh

@danidaryaweesh
Copy link

Thanks @TrevorSayre saved my day, your suggestion worked!

cunneen added a commit to cunneen/node-canvas that referenced this issue Jun 7, 2024
Added `python@3.12` and `python-setuptools` to instructions as per comments in Automattic#2371 and Automattic#2387
@zbjornson
Copy link
Collaborator

I updated the readme to list python-setuputils as a prereq on macOS. Thanks for the collective troubleshooting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants