简体   繁体   中英

npm not reading .npmrc file

I'm trying to install a library from a private repository, and I keep getting an error in trying to use npm.

I'm using: OSX Mavericks 10.9.3 Node v0.10.28 npm 1.4.10 (this was installed after trying with 1.4.13 and it still not working)

I am running this from my home directory, and the ~/.npmrc file is in the directory.

whenever I run the command: npm install 'library name here'

I get the following error:

npm http GET https://registry.npmjs.org/dslib-js
npm http 404 https://registry.npmjs.org/dslib-js
npm ERR! 404 404 Not Found: dslib-js
npm ERR! 404 
npm ERR! 404 'dslib-js' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it
npm ERR! 404 
npm ERR! 404 Maybe try 'npm search dslib'
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, or http url, or git url.

npm ERR! System Darwin 13.2.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "dslib-js"
npm ERR! cwd /Users/marcos.pedreiro
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.10
npm ERR! code E404
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/marcos.pedreiro/npm-debug.log
npm ERR! not ok code 0

Edits:

When I run ls -a (in the home directory) this is the output:

.           .ssh            Music
..          .subversion     Pictures
.CFUserTextEncoding .vagrant.d      Public
.DS_Store       Applications        VirtualBox VMs
.Trash          Desktop         clients
.bash_history       Documents       dev
.gradle         Downloads       npm-debug.log
.matlab         Google Drive        ~:.npmrc
.npm            Library         ~:.npmrc.template
.npmrc.bak      Movies

This is the output of the command npm config ls -l | grep config npm config ls -l | grep config

; cli configs
globalconfig = "/usr/local/etc/npmrc"
userconfig = "/Users/marcos.pedreiro/.npmrc"

:End Edits

Any help would be greatly appreciated. Thanks!

In my case the character encoding was wrong for some reason, I had to convert it to UTF-8.

I used "npm get" to discover the problem, the result was full of u/2411... strings.

If what you posted is truly the output of ls -a , then the filename is wrong.

~:.npmrc should be named .npmrc .

The ~ at the beginning suggests you used a shell shortcut to place the file in your home directory (maybe something like cp .npmrc ~:.npmrc . The trouble is likely the colon. ~/ will be interpreted as "my home directory", but ~something/ will be interpreted as the home directory of the user named something . Since there is no user something , the system is probably just treated ~: as literal text.

Try renaming the file and see if that works:

mv "~:.npmrc" .npmrc

In case it helps anyone landing here: I had a npm-shrinkwrap.json file in the project root that was overriding the registry config from .npmrc . Removing the shrinkwrap file solved the issue.

For people running Windows, check if Windows is hiding file extensions. For me, Windows was saying that the file name was .npmrc , but the real file name was .npmrc.txt .

Removing the .txt extension fixed the issue.

I'm assuming the Node package dslib-js is contained within your private npm repository. You'll need to set that repository in your local .npmrc file. For example, if your repository was at http://myrepo.com:4000 you would run the following command:

$ npm set registry "http://myrepo.com:4000"

The error your getting above is because the package dslib-js is not available on the npmjs.org, as you can see from visiting this URL: https://www.npmjs.org/package/dslib-js . By default (without a registry set in your .npmrc file), npm will search https://registry.npmjs.org (which can be browsed on the web via the URL I pasted above).

In case this helps anyone... my issue was I created the .npmrc file in a text editor so npm was ignoring the file because of the permissions on it. In order to fix it I deleted the file. Then I remade the file through the command line.

Cheers!

I missed a couple of things to download my packages published in my private repository.

First The file name was .npmrc.txt instead of .npmrc . In windows, you can't create file name directly. So I opened command prompt then fired

echo "auth_token" > .npmrc

Second I was just pasting my auth_token in .npmrc file. You have to append the registry address also.

//**.**.visualstudio.com/_packaging/**/npm/registry/:_authToken=token_here

Slightly different reason of npm not picking up the.npmrc. But after changing the registry setting in my project's.npmrc file I had to delete previously existing node_modules folder and package-lock.json, then install with npm install --save . Doesn't make much sense, but after this, the package-lock.json file (re)created was using the correct registry.

In case anyone has the same issue as me. We have a private registry but before adding the.npmrc file I tried running npm install . This created the package-lock.json and it was overriding the new registry that was added in the.npmrc file.

Simply deleting the package-lock.json and re-running npm install fixed it for me

I came across a scenario where npm ci was not picking/reading configs from .npmrc file.

Replacing it with npm install resolved the issue.

Node version 10.18.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM