capacitor-assets icon indicating copy to clipboard operation
capacitor-assets copied to clipboard

Unable to install on mac M1

Open FischerTech opened this issue 3 years ago • 34 comments

When I run sudo npm install -g cordova-res --unsafe-perm I get the following error.

npm ERR! code 1 npm ERR! path /usr/local/lib/node_modules/cordova-res/node_modules/sharp npm ERR! command failed npm ERR! command sh -c (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy) npm ERR! CC(target) Release/obj.target/nothing/../node-addon-api/nothing.o npm ERR! LIBTOOL-STATIC Release/nothing.a npm ERR! TOUCH Release/obj.target/libvips-cpp.stamp npm ERR! CXX(target) Release/obj.target/sharp/src/common.o npm ERR! info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.10.5/libvips-8.10.5-darwin-x64.tar.br npm ERR! internal/fs/utils.js:307 npm ERR! throw err; npm ERR! ^ npm ERR! npm ERR! Error: EACCES: permission denied, copyfile '/tmp/53567-libvips-8.10.5-darwin-x64.tar.br' -> '/Users/USERNAME/.npm/_libvips/libvips-8.10.5-darwin-x64.tar.br' npm ERR! at Object.copyFileSync (fs.js:1991:3) npm ERR! at WriteStream. (/usr/local/lib/node_modules/cordova-res/node_modules/sharp/install/libvips.js:133:16) npm ERR! at WriteStream.emit (events.js:315:20) npm ERR! at emitCloseNT (internal/streams/destroy.js:87:10) npm ERR! at processTicksAndRejections (internal/process/task_queues.js:79:21) { npm ERR! errno: -13, npm ERR! syscall: 'copyfile', npm ERR! code: 'EACCES', npm ERR! path: '/tmp/53567-libvips-8.10.5-darwin-x64.tar.br', npm ERR! dest: '/Users/USERNAME/.npm/_libvips/libvips-8.10.5-darwin-x64.tar.br' npm ERR! } 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 | x64 npm ERR! gyp info find Python using Python version 3.9.2 found at "/usr/local/opt/[email protected]/bin/python3.9" npm ERR! gyp info spawn /usr/local/opt/[email protected]/bin/python3.9 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 '/usr/local/lib/node_modules/cordova-res/node_modules/sharp/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/USERNAME/Library/Caches/node-gyp/14.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/USERNAME/Library/Caches/node-gyp/14.16.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/USERNAME/Library/Caches/node-gyp/14.16.0/<(target_arch)/node.lib', npm ERR! gyp info spawn args '-Dmodule_root_dir=/usr/local/lib/node_modules/cordova-res/node_modules/sharp', 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! warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: archive library: Release/nothing.a the table of contents is empty (no object file members in the library define global symbols) npm ERR! In file included from ../src/common.cc:24: npm ERR! /usr/local/include/vips/vips8:35:10: fatal error: 'glib-object.h' file not found npm ERR! #include <glib-object.h> npm ERR! ^~~~~~~~~~~~~~~ npm ERR! 1 error generated. npm ERR! make: *** [Release/obj.target/sharp/src/common.o] Error 1 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 (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23) npm ERR! gyp ERR! stack at ChildProcess.emit (events.js:315:20) npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) npm ERR! gyp ERR! System Darwin 20.3.0 npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" npm ERR! gyp ERR! cwd /usr/local/lib/node_modules/cordova-res/node_modules/sharp npm ERR! gyp ERR! node -v v14.16.0 npm ERR! gyp ERR! node-gyp -v v7.1.2 npm ERR! gyp ERR! not ok

Here is my environment info:

Ionic:

Ionic CLI : 6.13.1

Utility:

cordova-res : not installed native-run : not installed

System:

NodeJS : v14.16.0 npm : 7.6.3 OS : macOS Big Sur

FischerTech avatar Mar 18 '21 15:03 FischerTech

same error but i found a solution

https://sharp.pixelplumbing.com/install#apple-m1

-- node: 15.11.0 npm: 7.6.0 OS: macOS Bis Sur 11.2.3 (20D91)

julienmiclo avatar Mar 24 '21 10:03 julienmiclo

I had the same problem. I followed the link @julienmiclo posted and everything worked after i installed the sharp graphics library.

node v15.12.0 npm v7.6.3 darwin v11.2.3

donhmorris avatar Mar 27 '21 22:03 donhmorris

I'm still having issues even after installing Sharp with the --build-from-source flag

johnmckay-reward avatar Mar 31 '21 08:03 johnmckay-reward

@jmkni do you have more info? Node version, etc.

donhmorris avatar Mar 31 '21 17:03 donhmorris

@donhmorris Sure

Node version - v15.12.0 Npm version - v7.6.3

Error:

npm ERR! code 1
npm ERR! path /opt/homebrew/lib/node_modules/cordova-res/node_modules/sharp
npm ERR! command failed
npm ERR! command sh -c (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
npm ERR! CC(target) Release/obj.target/nothing/../node-addon-api/nothing.o
npm ERR!   LIBTOOL-STATIC Release/nothing.a
npm ERR!   TOUCH Release/obj.target/libvips-cpp.stamp
npm ERR!   CXX(target) Release/obj.target/sharp/src/common.o
npm ERR! info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.10.5/libvips-8.10.5-darwin-arm64v8.tar.br
npm ERR! ERR! sharp Prebuilt libvips 8.10.5 binaries are not yet available for darwin-arm64v8
npm ERR! info sharp Attempting to build from source via node-gyp but this may fail due to the above error
npm ERR! info sharp Please see https://sharp.pixelplumbing.com/install for required dependencies
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.2 found at "/opt/homebrew/opt/[email protected]/bin/python3.9"
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   '/opt/homebrew/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   '/opt/homebrew/lib/node_modules/cordova-res/node_modules/sharp/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/johnmckay/Library/Caches/node-gyp/15.12.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/johnmckay/Library/Caches/node-gyp/15.12.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/johnmckay/Library/Caches/node-gyp/15.12.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/opt/homebrew/lib/node_modules/cordova-res/node_modules/sharp',
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! warning: /Library/Developer/CommandLineTools/usr/bin/libtool: archive library: Release/nothing.a the table of contents is empty (no object file members in the library define global symbols)
npm ERR! ../src/common.cc:24:10: fatal error: 'vips/vips8' file not found
npm ERR! #include <vips/vips8>
npm ERR!          ^~~~~~~~~~~~
npm ERR! 1 error generated.
npm ERR! make: *** [Release/obj.target/sharp/src/common.o] Error 1
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 (/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:369:20)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
npm ERR! gyp ERR! System Darwin 20.3.0
npm ERR! gyp ERR! command "/opt/homebrew/Cellar/node/15.12.0/bin/node" "/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /opt/homebrew/lib/node_modules/cordova-res/node_modules/sharp
npm ERR! gyp ERR! node -v v15.12.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/johnmckay/.npm/_logs/2021-04-01T17_54_05_088Z-debug.log

Let me know if you'd like a copy of that log file.

Thanks

johnmckay-reward avatar Apr 01 '21 17:04 johnmckay-reward

I suggest trying again. it looks like the binaries are out now. Make sure your terminal is not running under rosetta.

npm -g i sharp npm -g i cordova-res

donhmorris avatar Apr 01 '21 18:04 donhmorris

Still getting the same issue unfortunately @donhmorris , and not running under Rosetta!

johnmckay-reward avatar Apr 01 '21 19:04 johnmckay-reward

I wish i could help more. I got this to work while trying to build the native (IOS and Android) versions of my app. I did a lot of stuff to get the capacitor build tool to work. One of the thing i had to do was install cocoapods using the -acrh64 flag. Unfortunately its all jumbled together and I can't remember which step fixed what. I do know that I can install and use the cordova-res tool with no problems now.

donhmorris avatar Apr 02 '21 15:04 donhmorris

No worries @donhmorris , appreciate the replies!

I still have my Intel machine so using that in the mean time, so not slowing me down :)

Thanks

johnmckay-reward avatar Apr 02 '21 18:04 johnmckay-reward

@donhmorris Even though the new binaries are available, they will only install with 0.28 and up. I tried installing this specific version in my project but the install script still sticks to 0.27.2 even if you do npm i [email protected]. I think this will only work correctly if cordova-res updates their dependency to 0.28.X

See: https://github.com/lovell/sharp-libvips/issues/71

kawazoe avatar May 03 '21 19:05 kawazoe

ok, thanks

donhmorris avatar May 03 '21 20:05 donhmorris

@donhmorris there is a PR for this: https://github.com/ionic-team/cordova-res/pull/216

Is there a timeline for the merge & release?

ikosta avatar Jun 02 '21 11:06 ikosta

@imhoffd forgot to tag you in the comment above

ikosta avatar Jun 02 '21 11:06 ikosta

@imhoffd Please have a look into this PR #216

ikosta avatar Jun 08 '21 13:06 ikosta

Any work around to install it until #216 gets merged?

fr3fou avatar Jul 01 '21 16:07 fr3fou

I use the following command to install the npm package of the MR:

npm install -g https://github.com/rubenstolk/cordova-res/tarball/patch-1

@fr3fou

MaaxGr avatar Jul 06 '21 18:07 MaaxGr

many thanks @MaaxGr ! I also need to do cd /opt/homebrew/lib/node_modules/cordova-res and npm install to create the dist folder

davidecampello avatar Jul 07 '21 18:07 davidecampello

@MaaxGr thanks for solution and @davidecampello thanks for the clue!

I'm using nvm and I do

cd /Users/monurakkaya/.nvm/versions/node/v14.17.1/lib/node_modules/cordova-res && npm install && npm run build

In my case I also needed to run npm run build

monurakkaya avatar Jul 07 '21 19:07 monurakkaya

I've globally installed the patch mentioned by @MaaxGr and ran npm install in the cordova-res folder (also using nvm) but I can't seem to run the build command:

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `tsc`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/adam/.npm/_logs/2021-10-14T11_27_43_749Z-debug.log

Contents of the folder:

drwxr-xr-x    8 adam  staff     256 Oct 14 13:26 .
drwxr-xr-x   12 adam  staff     384 Oct 14 13:19 ..
-rw-r--r--    1 adam  staff    1072 Oct 26  1985 LICENSE
-rw-r--r--    1 adam  staff    3887 Oct 26  1985 README.md
drwxr-xr-x    3 adam  staff      96 Oct 14 13:13 bin
drwxr-xr-x  652 adam  staff   20864 Oct 14 13:26 node_modules
-rw-r--r--    1 adam  staff  415624 Oct 14 13:26 package-lock.json
-rw-r--r--    1 adam  staff    2782 Oct 14 13:25 package.json

I suppose I'm missing files here?

EDIT: I was running node 14, switching to the following version fixed my problem: node v15.14.0 npm 7.7.6 using npm -g i cordova-res

adamk22 avatar Oct 14 '21 11:10 adamk22

I have found running latest node 16 works best for me. Prior to m1, I ran the lts version of node.

donhmorris avatar Oct 14 '21 13:10 donhmorris

I'm on a MacBook Air with the M1 chip.

node v16.11.1 npm v8.0.0

I was seeing the exact error mentioned by jmkni. Running brew install vips fixed the issue for me (install took some time).

jwt02180 avatar Oct 19 '21 14:10 jwt02180

I'm on a MacBook Air with the M1 chip.

node v16.11.1 npm v8.0.0

I was seeing the exact error mentioned by jmkni. Running brew install vips fixed the issue for me (install took some time).

This is the solution that worked in my case: MacBook Pro 16" with M1 Max chip.

lincolnberryiii avatar Oct 26 '21 22:10 lincolnberryiii

Thanks everyone, will make sure to bump the versions of sharp when we release 1.0. Keep in mind Cordova support will be dropped from 1.0 and it will be Capacitor only. Happy to do a patch release before that for older versions if you still need Cordova support.

mlynch avatar Oct 31 '21 13:10 mlynch

brew install vips

This worked for me too on M1 Pro chip, though had to also run brew install libheif.

hardikdabhi avatar Nov 02 '21 01:11 hardikdabhi

Thank you @hardikdabhi

adelabd avatar Nov 07 '21 02:11 adelabd

I'm on a MacBook Air with the M1 chip.

node v16.11.1 npm v8.0.0

I was seeing the exact error mentioned by jmkni. Running brew install vips fixed the issue for me (install took some time).

This works for me on M1 Pro

npm install -g --arch=arm64 --platform=darwin sharp
brew install vips

PvasquezF avatar Nov 12 '21 20:11 PvasquezF

@mlynch I think it would be quite unwise to drop Cordova support for this library.

Two reasons:

  • keeping Cordova compatibility should be a trivial affair nowadays, I'm happy to do that work if someone wants to do it
  • Cordova is not deprecated, it's still an active Apache supported project and has an active community that could use this
  • While I don't mind migrating to Capacitor from Cordova eventually if that's where things end up, there's little reason to do so right now, and cutting off Cordova users will just cause fragmentation as a fork will likely be fired up

jpike88 avatar Nov 23 '21 07:11 jpike88

@jpike88 appreciate the feedback. For Cordova users they can still stick with the cordova-res tool that will continue to work, so no problems there. Happy to do a patch release for that version as well for this M1 fix.

Moving forward, we think Capacitor provides a much better developer experience and we're starting to build out a whole ecosystem of functionality around it (for example, the new Capacitor Configure utility we released a few weeks ago). We really want to encourage developers to make the switch to Capacitor because we know they'll be happier and will be better aligned with the rest of the Ionic stack and where we're taking it. And, at the end of the day, it has a non-zero cost for us to build Cordova and Capacitor versions of things and we think that energy would be better spent innovating on top of the superior foundation that Capacitor affords us.

mlynch avatar Nov 23 '21 14:11 mlynch

PR https://github.com/ionic-team/capacitor-assets/pull/262 should fix the issue;

https://github.com/lovell/sharp/issues/2460#issuecomment-811046375

alexcroox avatar Dec 03 '21 10:12 alexcroox

It's fixed

ikosta avatar Dec 16 '21 19:12 ikosta