node.js 如何添加 .npmrc 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42877722/
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
How can I add a .npmrc file?
提问by Rohit Srivastava
I installed node on my Mac OS Sierra. I use Windows at my work so there I have a .npmrc file in the node folder but I don't seem to find that in mac. The problem is I want to add a registry of the format
我在 Mac OS Sierra 上安装了节点。我在工作中使用 Windows,所以我在 node 文件夹中有一个 .npmrc 文件,但我似乎没有在 mac 中找到它。问题是我想添加格式的注册表
"scope=rohit-project@rohit-aquila:registry=https://registry.npmjs.org/
//registry.npmjs.org/:_authToken=03408522-4rfca-dff4f-dfsf-43863gfe3492"
How do I add it so that I can install the dependencies and modules for my project by running npm install on MAC OS Sierra.
如何添加它,以便我可以通过在 MAC OS Sierra 上运行 npm install 来为我的项目安装依赖项和模块。
I created a .npmrc file simply and added the above code...and therefater running npm install I get the following error
我简单地创建了一个 .npmrc 文件并添加了上面的代码......然后运行 npm install 我收到以下错误
rohitsrivastava$ npm install
npm ERR! Darwin 16.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v7.7.3
npm ERR! npm v4.1.2
npm ERR! code E404
npm ERR! 404 Not found : @rohit-project/notes
npm ERR! 404
npm ERR! 404 '@rohit-project/notes' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of '@rohit-project/mega'
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
回答by oligofren
There are a few different points here:
这里有几个不同的点:
- Where is the
.npmrcfile created. - How can you download private packages
.npmrc创建的文件在哪里。- 你如何下载私人包
Running npm config ls -lwill show you all the implicit settings for npm, including what it thinks is the right place to put the .npmrc. But if you have never logged in (using npm login) it will be empty. Simply log in to create it.
运行npm config ls -l将向您显示 npm 的所有隐式设置,包括它认为放置.npmrc. 但是,如果您从未登录过(使用npm login),它将是空的。只需登录即可创建。
Another thing is #2. You can actually do that by putting a .npmrcfile in the NPM package's root. It will then be used by NPM when authenticating. It also supports variable interpolation from your shell so you could do stuff like this:
另一件事是#2。您实际上可以通过.npmrc在 NPM 包的根目录中放置一个文件来做到这一点。然后 NPM 将在进行身份验证时使用它。它还支持来自您的 shell 的变量插值,因此您可以执行以下操作:
; Get the auth token to use for fetching private packages from our private scope
; see http://blog.npmjs.org/post/118393368555/deploying-with-npm-private-modules
; and also https://docs.npmjs.com/files/npmrc
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
Pointers
指针
回答by Rahul Hirve
This issue is because of you having some local or private packages.
For accessing those packages you have to create .npmrcfile for this issue. Just refer the following link for your solution. https://nodesource.com/blog/configuring-your-npmrc-for-an-optimal-node-js-environment
这个问题是因为你有一些本地或私人包。要访问这些包,您必须.npmrc为此问题创建文件。只需参考以下链接即可获得解决方案。https://nodesource.com/blog/configuring-your-npmrc-for-an-optimal-node-js-environment
回答by Mayank
Assuming you are using VSTS run vsts-npm-auth -config .npmrcto generate new .npmrc file with the auth token
假设您正在使用 VSTS runvsts-npm-auth -config .npmrc生成带有 auth 令牌的新 .npmrc 文件

