关于 Node.js scoped module 的一些理解

简介: 关于 Node.js scoped module 的一些理解

看这样一条命令:


npm install @angular/router --save


这个 @angular/router 代表什么含义?


我们使用下面的命令,无法搜索到这个包:


npm search @angular/router

:No match found for “@angular/router”


这是 NPM 的一个新特性,称为“作用域包”,它有效地允许 NPM 包被命名空间。 NPM 上的每个用户和组织都有自己的范围,他们是唯一可以向其中添加包的人。


这很有用,原因有几个:


它允许组织明确哪些软件包是“官方的”,哪些不是。

例如,如果一个包的范围为 @angular,你就知道它是由 Angular 核心团队发布的。


包名只需要在它发布的范围内是唯一的,而不是整个注册表。

例如,主存储库中已经采用了包名称 http,但 Angular 也可以使用 @angular/http。


范围包没有出现在公共搜索中的原因是因为它们中的很多是由使用 NPM 付费服务的组织创建的私有包,并且他们不愿意打开搜索,直到他们完全确定他们不是将不应该公开的任何内容公开 - 从法律角度来看,这是可以理解的。


npm 上基本上有两种类型的模块,它们是:


(1) 全局模块 - 这些模块遵循当今存在的命名约定。 您需要(‘foo’)并且非常高兴。 它们由一个或多个人通过 npm install XYZ 命令拥有。


(2) 作用域模块 - 这些是在组织名称下“作用域”的新模块,该组织名称以 @ 组织名称、斜杠和包名开头,例如 @someOrgScope/包名。 作用域是将相关包组合在一起的一种方式,也会影响 npm 处理包的方式。


作用域包是通过在 npm install 中通过名称引用它来安装的,前面是 @-symbol:


npm install @myorg/mypackage

作用域是将相关包组合在一起的一种方式,也会影响 npm 处理包的方式。 每个 npm 用户/组织都有自己的范围,只有您可以在您的范围内添加包。 这意味着您不必担心有人在您之前拿走您的包裹名称。 因此,这也是向组织发出官方软件包信号的好方法。


SAP Spartacus 也使用了大量的 scoped module,如下图所示:

image.png

相关文章
|
4月前
|
JavaScript
node下的two.js调用one.js出现无法编译问题 Cannot find module ‘c:
node下的two.js调用one.js出现无法编译问题 Cannot find module ‘c:
48 0
|
6月前
|
JavaScript
Syntax Error: Error: Cannot find module ‘node-sass‘
Syntax Error: Error: Cannot find module ‘node-sass‘
67 0
|
6月前
|
小程序
小程序wepy踩坑-Cannot find module 'D:\node_modules\npm\bin\npm-cli.js'
小程序wepy踩坑-Cannot find module 'D:\node_modules\npm\bin\npm-cli.js'
110 0
|
29天前
报错/ ./node_modules/axios/lib/platform/index.js Module parse failed: Unexpected token (5:2)怎么解决?
报错/ ./node_modules/axios/lib/platform/index.js Module parse failed: Unexpected token (5:2)怎么解决?
|
6月前
|
资源调度 JavaScript
yarn错误The engine “node“ is incompatible with this module
yarn错误The engine “node“ is incompatible with this module
|
8天前
|
资源调度 JavaScript 内存技术
error @achrinza/node-ipc@9.2.2: The engine “node“ is incompatible with this module. Expected version
error @achrinza/node-ipc@9.2.2: The engine “node“ is incompatible with this module. Expected version
|
2月前
Module build failed (from ./node_modules/eslint-loader/index.js)
Module build failed (from ./node_modules/eslint-loader/index.js)
91 0
Module build failed (from ./node_modules/eslint-loader/index.js)
|
6月前
|
资源调度
Cannot find module ‘\node_modules\ejs\postinstall.js
Cannot find module ‘\node_modules\ejs\postinstall.js
40 0
|
7月前
|
前端开发
【前端异常】Module build failed: Error: ENOENT: no such file or directory, scandir ‘G:\OPWeb\public\node_m
【前端异常】Module build failed: Error: ENOENT: no such file or directory, scandir ‘G:\OPWeb\public\node_m
73 0
|
5月前
(node)Warning: Accessing non-existent property ‘xxx‘ of module exports inside circular depen
(node)Warning: Accessing non-existent property ‘xxx‘ of module exports inside circular depen