node.js npm 不读取 .npmrc 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23899093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
npm not reading .npmrc file
提问by Maverick
I'm trying to install a library from a private repository, and I keep getting an error in trying to use npm.
我正在尝试从私有存储库安装一个库,但在尝试使用 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)
我正在使用:OSX Mavericks 10.9.3 Node v0.10.28 npm 1.4.10(这是在尝试使用 1.4.13 后安装的,但仍然无法正常工作)
I am running this from my home directory, and the ~/.npmrcfile is in the directory.
我从我的主目录运行它,~/.npmrc文件在目录中。
whenever I run the command: npm install 'library name here'
每当我运行命令时: 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:
当我运行ls -a(在主目录中)时,这是输出:
. .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!
任何帮助将不胜感激。谢谢!
采纳答案by Brandon
If what you posted is truly the output of ls -a, then the filename is wrong.
如果您发布的内容确实是 的输出ls -a,则文件名是错误的。
~:.npmrcshould be named .npmrc.
~:.npmrc应命名.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.
开头的 ~ 建议您使用 shell 快捷方式将文件放置在您的主目录中(可能类似于cp .npmrc ~:.npmrc. 问题可能是冒号。 ~/将被解释为“我的主目录”,但~something/将被解释为用户名为something。由于没有用户something,系统可能只是将 ~: 视为文字文本。
Try renaming the file and see if that works:
尝试重命名文件,看看是否有效:
mv "~:.npmrc" .npmrc
回答by Segimerus
In my case the character encoding was wrong for some reason, I had to convert it to UTF-8.
在我的情况下,由于某种原因字符编码是错误的,我不得不将其转换为 UTF-8。
I used "npm get" to discover the problem, the result was full of u/2411... strings.
我用“npm get”来发现问题,结果全是 u/2411... 字符串。
回答by Pedro
In case it helps anyone landing here: I had a npm-shrinkwrap.jsonfile in the project root that was overriding the registryconfig from .npmrc. Removing the shrinkwrap file solved the issue.
在情况下,它可以帮助任何人登陆这里:我有一个npm-shrinkwrap.json项目根这是压倒一切的文件registry从配置.npmrc。删除shrinkwrap 文件解决了这个问题。
回答by AJ Richardson
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.
对于运行 Windows 的用户,请检查 Windows 是否隐藏了文件扩展名。对我来说,Windows 说文件名是.npmrc,但真正的文件名是.npmrc.txt.
Removing the .txtextension fixed the issue.
删除.txt扩展解决了这个问题。
回答by dylants
I'm assuming the Node package dslib-jsis contained within your private npm repository. You'll need to set that repository in your local .npmrcfile. For example, if your repository was at http://myrepo.com:4000you would run the following command:
我假设 Node 包dslib-js包含在您的私有 npm 存储库中。您需要在本地.npmrc文件中设置该存储库。例如,如果您的存储库在,http://myrepo.com:4000您将运行以下命令:
$ npm set registry "http://myrepo.com:4000"
The error your getting above is because the package dslib-jsis 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 .npmrcfile), npm will search https://registry.npmjs.org(which can be browsed on the web via the URL I pasted above).
您上面的错误是因为该包dslib-js在 npmjs.org 上不可用,您可以通过访问此 URL 看到:https://www.npmjs.org/package/dslib-js 。默认情况下(没有在您的.npmrc文件中设置注册表),npm 将进行搜索https://registry.npmjs.org(可以通过我上面粘贴的 URL 在网络上浏览)。
回答by rardoz
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.
如果这对任何人有帮助...我的问题是我在文本编辑器中创建了 .npmrc 文件,因此 npm 由于其权限而忽略了该文件。为了修复它,我删除了该文件。然后我通过命令行重新制作了文件。
Cheers!
干杯!
回答by Sunil Garg
I missed a couple of things to download my packages published in my private repository.
我错过了一些东西来下载我在我的私人存储库中发布的包。
FirstThe file name was .npmrc.txtinstead of .npmrc. In windows, you can't create file name directly. So I opened command prompt then fired
首先文件名是.npmrc.txt而不是.npmrc. 在 Windows 中,您不能直接创建文件名。所以我打开命令提示符然后开火
echo "auth_token" > .npmrc
SecondI was just pasting my auth_tokenin .npmrcfile. You have to append the registry address also.
其次,我只是粘贴我auth_token的.npmrc文件。您还必须附加注册表地址。
//**.**.visualstudio.com/_packaging/**/npm/registry/:_authToken=token_here
回答by HiRenS
I came across a scenario where npm ciwas not picking/reading configs from .npmrc file.
我遇到了一个npm ci没有从 .npmrc 文件中选择/读取配置的场景。
Replacing it with npm installresolved the issue.
替换它npm install解决了问题。
Node version 10.18.0
节点版本 10.18.0

