Installing old npm packages on m1 mac workaround

실리콘·2023년 1월 25일
0

I had problem with installing electron v8.1.1 for m1 mac

npm ERR! code 1
npm ERR! path /path/to/my/project/node_modules/electron
npm ERR! command failed
npm ERR! command sh -c node install.js
npm ERR! node:internal/process/promises:246
npm ERR!           triggerUncaughtException(err, true /* fromPromise */);
npm ERR!           ^
npm ERR! 
npm ERR! GotError [HTTPError]: Response code 404 (Not Found) for https://github.com/electron/electron/releases/download/v8.1.1/electron-v8.1.1-darwin-arm64.zip

It says darwin-arm64 v8.1.1 electron doesn't exist.
Makes sense because
m1 mac release was 11/17, 2020
electron v8.1.1 was 3/10, 2020

So how to solve?
arch -x86_64 [:args]
don't know how arch command works, but this fixed the problem for me
note that program started in this manner, and its child process will try to inherit architecture all the same
so if i start a zsh session with arch -x86_64, other programs invoked from this shell will also try to mimic architecture

way 1

launch the shell with different architecture, and use node with nvm

nvm install [:temp node version]
nvm use [:temp node version]
nvm uninstall [:target node version] # if installed already
arch -x86_64 zsh  # launch a zsh session with -x86_64 architecture.
arch  # check architecture.  might result in i386 also.
nvm install [:target node version]
nvm use [:target node version] # install and use target npm

way 2

not tested
run npm i with designated architecture

arch -x86_64 npm i

reference:
https://stackoverflow.com/questions/68896696/having-trouble-installing-npm-on-mac-m1
https://news.ycombinator.com/item?id=25132217#:~:text=Stickiness%20of%20architecture

profile
software engineer

0개의 댓글