node-gd icon indicating copy to clipboard operation
node-gd copied to clipboard

npm i node-gd and error

Open MrMaxorz opened this issue 3 years ago • 7 comments

When I do npm i node-gd I found this error:

npm ERR! code 1 npm ERR! path /Users/Maxorz/Works/Longdo/thaimap-services/node_modules/node-gd npm ERR! command failed npm ERR! command sh -c node-gyp rebuild npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using [email protected] npm ERR! gyp info using [email protected] | darwin | arm64 npm ERR! gyp info find Python using Python version 3.9.13 found at "/opt/homebrew/opt/[email protected]/bin/python3.9" npm ERR! (node:15733) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only. npm ERR! (Use node --trace-deprecation ... to show where the warning was created) npm ERR! gyp info spawn /opt/homebrew/opt/[email protected]/bin/python3.9 npm ERR! gyp info spawn args [ npm ERR! gyp info spawn args '/Users/Maxorz/Works/Longdo/thaimap-services/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/Maxorz/Works/Longdo/thaimap-services/node_modules/node-gd/build/config.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '/Users/Maxorz/Works/Longdo/thaimap-services/node_modules/node-gyp/addon.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '/Users/Maxorz/Library/Caches/node-gyp/16.16.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/Maxorz/Library/Caches/node-gyp/16.16.0', npm ERR! gyp info spawn args '-Dnode_gyp_dir=/Users/Maxorz/Works/Longdo/thaimap-services/node_modules/node-gyp', npm ERR! gyp info spawn args '-Dnode_lib_file=/Users/Maxorz/Library/Caches/node-gyp/16.16.0/<(target_arch)/node.lib', npm ERR! gyp info spawn args '-Dmodule_root_dir=/Users/Maxorz/Works/Longdo/thaimap-services/node_modules/node-gd', 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! gyp info spawn make npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ] npm ERR! xcrun: error: active developer path ("/Applications/Xcode.app/Contents/Developer") does not exist npm ERR! Use sudo xcode-select --switch path/to/Xcode.app to specify the Xcode that you wish to use for command line developer tools, or use xcode-select --install to install the standalone command line developer tools. npm ERR! See man xcode-select for more details. npm ERR! gyp ERR! build error npm ERR! gyp ERR! stack Error: make failed with exit code: 1 npm ERR! gyp ERR! stack at ChildProcess.onExit (/Users/Maxorz/Works/Longdo/thaimap-services/node_modules/node-gyp/lib/build.js:194:23) npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:527:28) npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12) npm ERR! gyp ERR! System Darwin 21.5.0 npm ERR! gyp ERR! command "/opt/homebrew/Cellar/node@16/16.16.0/bin/node" "/Users/Maxorz/Works/Longdo/thaimap-services/node_modules/.bin/node-gyp" "rebuild" npm ERR! gyp ERR! cwd /Users/Maxorz/Works/Longdo/thaimap-services/node_modules/node-gd npm ERR! gyp ERR! node -v v16.16.0 npm ERR! gyp ERR! node-gyp -v v5.1.1 npm ERR! gyp ERR! not ok

How can I fix this issue? I already install brew install pkg-config gd

System Version: macOS 12.4 (21F79) Macbook pro M1

MrMaxorz avatar Aug 26 '22 11:08 MrMaxorz

Hi, Isn't this message the solution?

npm ERR! Use sudo xcode-select --switch path/to/Xcode.app to specify the Xcode that you wish to use for command line developer tools, or use xcode-select --install to install the standalone command line developer tools.

Cheers Vincent

y-a-v-a avatar Aug 26 '22 11:08 y-a-v-a

Thanks for response.

After I fix Xcode now I found this error:

npm ERR! code 1 npm ERR! path /Users/Maxorz/Works/Longdo/thaimap-services/node_modules/node-gd npm ERR! command failed npm ERR! command sh -c node-gyp rebuild npm ERR! CC(target) Release/obj.target/nothing/../node-addon-api/nothing.o npm ERR! LIBTOOL-STATIC Release/nothing.a npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using [email protected] npm ERR! gyp info using [email protected] | darwin | arm64 npm ERR! gyp info find Python using Python version 3.8.9 found at "/Library/Developer/CommandLineTools/usr/bin/python3" npm ERR! (node:4115) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only. npm ERR! (Use node --trace-deprecation ... to show where the warning was created) npm ERR! gyp info spawn /Library/Developer/CommandLineTools/usr/bin/python3 npm ERR! gyp info spawn args [ npm ERR! gyp info spawn args '/Users/Maxorz/Works/Longdo/thaimap-services/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/Maxorz/Works/Longdo/thaimap-services/node_modules/node-gd/build/config.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '/Users/Maxorz/Works/Longdo/thaimap-services/node_modules/node-gyp/addon.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '/Users/Maxorz/Library/Caches/node-gyp/16.16.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/Maxorz/Library/Caches/node-gyp/16.16.0', npm ERR! gyp info spawn args '-Dnode_gyp_dir=/Users/Maxorz/Works/Longdo/thaimap-services/node_modules/node-gyp', npm ERR! gyp info spawn args '-Dnode_lib_file=/Users/Maxorz/Library/Caches/node-gyp/16.16.0/<(target_arch)/node.lib', npm ERR! gyp info spawn args '-Dmodule_root_dir=/Users/Maxorz/Works/Longdo/thaimap-services/node_modules/node-gd', 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! gyp info spawn make npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ] npm ERR! env: python: No such file or directory npm ERR! make: *** [Release/nothing.a] Error 127 npm ERR! gyp ERR! build error npm ERR! gyp ERR! stack Error: make failed with exit code: 2 npm ERR! gyp ERR! stack at ChildProcess.onExit (/Users/Maxorz/Works/Longdo/thaimap-services/node_modules/node-gyp/lib/build.js:194:23) npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:527:28) npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12) npm ERR! gyp ERR! System Darwin 21.5.0 npm ERR! gyp ERR! command "/opt/homebrew/Cellar/node@16/16.16.0/bin/node" "/Users/Maxorz/Works/Longdo/thaimap-services/node_modules/.bin/node-gyp" "rebuild" npm ERR! gyp ERR! cwd /Users/Maxorz/Works/Longdo/thaimap-services/node_modules/node-gd npm ERR! gyp ERR! node -v v16.16.0 npm ERR! gyp ERR! node-gyp -v v5.1.1 npm ERR! gyp ERR! not ok

MrMaxorz avatar Aug 26 '22 12:08 MrMaxorz

no luck with this issue 😭

$npm install node-gd npm WARN deprecated [email protected]: this library is no longer supported npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142 npm ERR! code 1 npm ERR! path /Users/Maxorz/Works/Longdo/thaimap-snippet/node_modules/node-gd npm ERR! command failed npm ERR! command sh /var/folders/pp/kfsc9n0j3b9221jz5znvsgt00000gn/T/install-5e70ca68.sh npm ERR! CC(target) Release/obj.target/nothing/../node-addon-api/nothing.o npm ERR! LIBTOOL-STATIC Release/nothing.a npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using [email protected] npm ERR! gyp info using [email protected] | darwin | arm64 npm ERR! gyp info find Python using Python version 3.8.9 found at "/Library/Developer/CommandLineTools/usr/bin/python3" npm ERR! (node:38918) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only. npm ERR! (Use node --trace-deprecation ... to show where the warning was created) npm ERR! gyp info spawn /Library/Developer/CommandLineTools/usr/bin/python3 npm ERR! gyp info spawn args [ npm ERR! gyp info spawn args '/Users/Maxorz/Works/Longdo/thaimap-snippet/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/Maxorz/Works/Longdo/thaimap-snippet/node_modules/node-gd/build/config.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '/Users/Maxorz/Works/Longdo/thaimap-snippet/node_modules/node-gyp/addon.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '/Users/Maxorz/Library/Caches/node-gyp/16.17.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/Maxorz/Library/Caches/node-gyp/16.17.0', npm ERR! gyp info spawn args '-Dnode_gyp_dir=/Users/Maxorz/Works/Longdo/thaimap-snippet/node_modules/node-gyp', npm ERR! gyp info spawn args '-Dnode_lib_file=/Users/Maxorz/Library/Caches/node-gyp/16.17.0/<(target_arch)/node.lib', npm ERR! gyp info spawn args '-Dmodule_root_dir=/Users/Maxorz/Works/Longdo/thaimap-snippet/node_modules/node-gd', 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! gyp info spawn make npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ] npm ERR! env: python: No such file or directory npm ERR! make: *** [Release/nothing.a] Error 127 npm ERR! gyp ERR! build error npm ERR! gyp ERR! stack Error: make failed with exit code: 2 npm ERR! gyp ERR! stack at ChildProcess.onExit (/Users/Maxorz/Works/Longdo/thaimap-snippet/node_modules/node-gyp/lib/build.js:194:23) npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:513:28) npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12) npm ERR! gyp ERR! System Darwin 21.5.0 npm ERR! gyp ERR! command "/opt/homebrew/Cellar/node@16/16.17.0/bin/node" "/Users/Maxorz/Works/Longdo/thaimap-snippet/node_modules/.bin/node-gyp" "rebuild" npm ERR! gyp ERR! cwd /Users/Maxorz/Works/Longdo/thaimap-snippet/node_modules/node-gd npm ERR! gyp ERR! node -v v16.17.0 npm ERR! gyp ERR! node-gyp -v v5.1.1 npm ERR! gyp ERR! not ok

I try for new install brew and npm but it's not working. so sad 😢

These are my reproduction steps:

  1. Reinstall brew
  2. brew install node@16
  3. brew install pkg-config gd
  4. npm install node-gd
  5. then the error log shows

MrMaxorz avatar Aug 26 '22 15:08 MrMaxorz

try to run this:

$npm test

> [email protected] pretest
> node-gyp build -j max

gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | arm64
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build', '--jobs', 8 ]
  CXX(target) Release/obj.target/node_gd/src/addon.o
In file included from ../src/addon.cc:19:
../src/node_gd.h:22:10: fatal error: 'gd.h' file not found
#include <gd.h>
         ^~~~~~
1 error generated.
make: *** [Release/obj.target/node_gd/src/addon.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/Maxorz/Downloads/node-gd-master/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
gyp ERR! System Darwin 21.5.0
gyp ERR! command "/opt/homebrew/Cellar/node@16/16.17.0/bin/node" "/Users/Maxorz/Downloads/node-gd-master/node_modules/.bin/node-gyp" "build" "-j" "max"
gyp ERR! cwd /Users/Maxorz/Downloads/node-gd-master
gyp ERR! node -v v16.17.0
gyp ERR! node-gyp -v v9.0.0
gyp ERR! not ok 

MrMaxorz avatar Aug 29 '22 15:08 MrMaxorz

may be this issue found only in arm64

MrMaxorz avatar Aug 30 '22 09:08 MrMaxorz

You're correct, this is an ARM only issue and I've been having it for a while now. It does not compile on neither mac M1 nor M2.

vitorbertolucci avatar Sep 08 '22 12:09 vitorbertolucci

I managed to make it work on my Macbook M2.

There are two problems:

1 - node-gd requires an older version of Python, so you need to install Python 2.7.18 from https://www.python.org/downloads/release/python-2718/

2 - node-gyp is cannot locate the gd files (gd.h, gd_io.h and so on) on the directories /opt/homebrew/include/ and /otp/homebrew/lib/, since it only looks for them on /usr/local/*. I've tried creating a symlink, but since the files under those directories are symlinks themselves I ended up having the Too many levels of symlinks error.

So I decided to simply copy the required files to /usr/local and it worked.

sudo cp -R /opt/homebrew/include/* /usr/local/include
sudo cp -R /otp/homebrew/lib/* /usr/local/lib

I'm sure there must be a more elegant way to solve this, but at least I'm no longer stuck with this issue.

vitorbertolucci avatar Sep 08 '22 14:09 vitorbertolucci

I found the solution. You must set the environment variable

CPLUS_INCLUDE_PATH=/opt/homebrew/include LD_LIBRARY_PATH=/opt/homebrew/lib LIBRARY_PATH=/opt/homebrew/lib

Reference: https://github.com/Automattic/node-canvas/issues/1733

hknguyenvu avatar May 24 '23 16:05 hknguyenvu

I found the solution. You must set the environment variable

CPLUS_INCLUDE_PATH=/opt/homebrew/include LD_LIBRARY_PATH=/opt/homebrew/lib LIBRARY_PATH=/opt/homebrew/lib

Reference: Automattic/node-canvas#1733

I ended up forking the project with a fix so I don't have to keep fixing it every time, you can find it here: https://github.com/vitorbertolucci/node-gd

It's also published on npm at https://www.npmjs.com/package/@vitorbertolucci/node-gd

vitorbertolucci avatar May 24 '23 19:05 vitorbertolucci

Thanks. However I think I will stick with the original ^^

hknguyenvu avatar May 25 '23 08:05 hknguyenvu

Just release v3.0.0 that might fix the M1 and M2 issues.

y-a-v-a avatar Jun 05 '23 13:06 y-a-v-a

For now I'd like to close this ticket, if one has any findings with regard to M1 and/or M2, please open a new ticket so I can take a look. Thanks in advance.

y-a-v-a avatar Jun 05 '23 19:06 y-a-v-a