Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having trouble installing npm on mac M1

npm WARN old lockfile 
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile 
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile 
npm WARN deprecated [email protected]: versions < v5.0.0 do not handle NUL in passwords properly
npm ERR! code 1
npm ERR! path /Users/nikhil/Desktop/admin/myprivatescout-master/node_modules/node
npm ERR! command failed
npm ERR! command sh -c node installArchSpecificPackage
npm ERR! npm ERR! code ETARGET
npm ERR! npm ERR! notarget No matching version found for [email protected].
npm ERR! npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! npm ERR! notarget a package version that doesn't exist.
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /Users/nikhil/.npm/_logs/2021-08-23T17_20_39_011Z-debug.log
npm ERR! node:internal/modules/cjs/loader:936
npm ERR!   throw err;
npm ERR!   ^
npm ERR! 
npm ERR! Error: Cannot find module 'node-darwin-arm64/package.json'
npm ERR! Require stack:
npm ERR! - /Users/nikhil/Desktop/admin/myprivatescout-master/node_modules/node/installArchSpecificPackage.js
npm ERR!     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
npm ERR!     at Function.resolve (node:internal/modules/cjs/helpers:100:19)
npm ERR!     at ChildProcess.<anonymous> (/Users/nikhil/Desktop/admin/myprivatescout-master/node_modules/node-bin-setup/index.js:18:27)
npm ERR!     at ChildProcess.emit (node:events:394:28)
npm ERR!     at maybeClose (node:internal/child_process:1067:16)
npm ERR!     at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5) {
npm ERR!   code: 'MODULE_NOT_FOUND',
npm ERR!   requireStack: [
npm ERR!     '/Users/nikhil/Desktop/admin/myprivatescout-master/node_modules/node/installArchSpecificPackage.js'
npm ERR!   ]
npm ERR! }

npm ERR! A complete log of this run can be found in:

npm ERR!     /Users/nikhil/.npm/_logs/2021-08-23T17_20_39_074Z-debug.log

I am unable to install any package in my project repository on my mac M1, already removed node_modules and package-lock.json and tried npm i after that.

tried running npm i, npm i for individual packages but couldn't fix it, Also tried installing with yarn but I am facing the same issue.

like image 978
Nikhil Avatar asked Aug 23 '21 17:08

Nikhil


People also ask

Does npm work on M1 Mac?

Currently, you can install Node natively on ARM (M1) by installing the latest version 15.6. 0 of Node. The older versions will still work, but they will need Rosetta 2 to run properly.

Why is my npm install failing?

The error in NPM, 'error package install failed, see above', can occur when the user creates a new project in Angular using Node. js using VS code. This means that NPM is corrupted in your system, and must reinstall NPM.

How do I resolve npm installation issues?

The easiest way to fix the issue is to pass an additional parameter –legacy-peer-deps to npm install. The --legacy-peer-deps tells the npm to ignore the peer dependencies and continue the installation of the package. Try the below command to install the dependencies for your project.


4 Answers

Add the architecture to the node:

$ nvm uninstall 14
$ arch -x86_64 zsh 
$ nvm install 14
$ nvm alias default 14

like image 165
Nikhil Avatar answered Nov 13 '22 12:11

Nikhil


The solution provided by Nikhil is a good start. However, this is more complete and applicable in more situations:

First, install nvm (Node version manager):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

Then, run the following command:

arch -x86_64 zsh 
like image 24
ralphjsmit Avatar answered Nov 13 '22 12:11

ralphjsmit


We had a dev with this problem, a M1 laptop bought new in December 2021. The solution by ralphjsmit got us part of the way.

We're using Nodejs v16.13.1. After running arch -x86_64 zsh the npm install still failed (Error: Cannot find module 'node-darwin-arm64/package.json').

arch returned i386.

The key for us was to re-install Nodejs (via nvm, nvm use v16.5.0 && nvm uninstall v16.13.1 && nvm install v16.13.1)

If I were to summarize all the steps we ran, they'd be

> node -v
v16.13.1
> node -p process.arch
arm64
> arch -x86_64 zsh
> nvm use 16.5.0 && nvm uninstall v16.13.1 && nvm install v16.13.1
nvm use 16.5.0 && nvm uninstall v16.13.1 && nvm install v16.13.1
Now using node v16.5.0 (npm v7.19.1)
Uninstalled node v16.13.1
Downloading and installing node v16.13.1...
... 
# output here, I am not on an M1 machine, but it mentions x64 in the name of the node binary file
...
Now using node v16.13.1 (npm v8.1.2)
> npm install
like image 43
severin Avatar answered Nov 13 '22 11:11

severin


It seems that reinstalling an older version of NodeJS (& NPM) helped me. Try version 14.18.3 from here.

like image 39
Dani Tseitlin Avatar answered Nov 13 '22 11:11

Dani Tseitlin