在节点模块名称中使用@ 符号 [英] Use of @ symbol in Node module names

查看:33
本文介绍了在节点模块名称中使用@ 符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看一位同事编写的一些代码,她在 require 语句中使用了 @ 符号.这是其中一个文件的第一行:

I'm looking at some code from a coworker wrote and she's using the @ symbol in require statements. This is the first line of one of these files:

var restServer = require('@company/config')

当我尝试运行此代码时,出现错误:

When I try to run this code, I get an error:

错误:找不到模块@company/config"

坦率地说,我期望的是,我的目录中没有任何看起来像这样的东西需要识别!似乎这里发生了一些魔法,我讨厌它.

Which I frankly expect, there's nothing that looks like this in my directory for require to recognize! It seems like there's some magic going on here, which I hate.

我只能猜测,这要么是我没有接触过的一些晦涩难懂的 npm 或 Node 技巧,要么可能是我没有了解其他一些配置的黑暗艺术.感谢任何信息,即使它只是对 @ 如何与 require 一起工作的解释.

All I can guess is that either this is some obscure npm or Node trick that I haven't been exposed to, or maybe that there's some other dark art of configuration that I'm not getting. Any info appreciated, even if it's just an explanation of how @ works with require.

其他想法:厨师参与了整个事情的某个地方,所以这可能是相关的.

Other ideas: Chef is involved somewhere in this whole thing, so that might be relevant.

更新:99% 确定这是 npm config 在这一点上的工作方式的问题,但仍然不确定如何修复它.

Update: 99% certain this is an issue with the way npm config works at this point, but still unsure of how to go about fixing it.

Update2 基于我发现的一些东西:

Update2 based on some stuff I uncovered:

Dereks-MacBook-Pro:project-dir derekjanni$ npm config set //registry.npmjs.org/:authtoken $SECRET_TOKEN

Dereks-MacBook-Pro:project-dir derekjanni$ npm install
npm ERR! Darwin 15.0.0
npm ERR! argv "/usr/local/Cellar/node/5.5.0/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v5.5.0
npm ERR! npm  v3.5.3
npm ERR! code E404
npm ERR! 404 Not found : @company/config
npm ERR! 404  '@company/config' is not in the npm registry.

推荐答案

所以我自己解决了这个问题.

So I solved this one myself.

原来 @company/config 是我们的私有 NPM 存储库之一,托管在 npm 上,并通过此别名定义到内部 GitHub 存储库:它与 require<的方式无关/code> 有效.

Turns out @company/config is one of our private NPM repositories, hosted on npm and defined by this alias to an internal GitHub repository: it had nothing to do with how require works.

使用 @ 可能是也可能不是我不知道的用于私有 NPM 存储库的协议,如果您遇到这种情况,请记住这一点.

Using @ may or may not be a protocol that I was unaware of for private NPM repos, keep that in mind if you run into this.

这篇关于在节点模块名称中使用@ 符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆