【问题标题】:Excessive node modules with npm install in angular2 quickstart在 angular2 快速入门中使用 npm 安装过多的节点模块
【发布时间】:2016-04-11 08:07:48
【问题描述】:

节点/NPM 版本:

节点:v5.4.0,npm:3.3.12

我正在尝试按照 angular2 网站上的快速入门教程来学习 Angular2。

Angular2 Quickstart

这是我的 package.json 文件(与教程中的完全相同)。

    {
  "name": "angular2-quickstart",
  "version": "1.0.0",
  "scripts": {
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lite": "lite-server",
    "start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
  },
  "license": "ISC",
  "dependencies": {
    "angular2": "2.0.0-beta.0",
    "systemjs": "0.19.6",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.0",
    "zone.js": "0.5.10"
  },
  "devDependencies": {
    "concurrently": "^1.0.0",
    "lite-server": "^1.3.1",
    "typescript": "^1.7.3"
  }

当我运行 npm install 时,npm 会在 node_modules 文件夹中安装超过 90MB 的模块(几百个单独的模块)。

应该有这么多依赖吗?我觉得这太过分了,一定是出了什么问题。有什么建议或有没有人经历过类似的行为?

NPM 安装没有抛出任何错误。

该应用程序运行良好,但我无法找到有关该应用程序所有必需的 node_modules 的任何信息。谢谢。

【问题讨论】:

  • 我做了一些研究,发现新版本的 npm 执行“平面模块安装”(不再在依赖项中嵌套 node_module 文件夹)。所以这可以解释为什么依赖性似乎过度。但如果有人确认大约 90MB 的 node_module 目录大小,仍然会很棒。
  • 是的,我在研究前后也遇到过同样的问题,我发现这是因为更新版本的 npm。

标签: node.js npm angular package.json npm-install


【解决方案1】:

其实并不是所有的都是必要的。

例如:

"devDependencies": {
    "concurrently": "^1.0.0",
    "lite-server": "^1.3.1",
    "typescript": "^1.7.3"
}

typescript的模块可以去掉,不过据我所知angular2建议用typescript写代码,更安全,强类型。你也可以用js或者coffeescript,没什么大不了的。

最重要的模块是

"angular2": "2.0.0-beta.0",
"es6-promise": "^3.0.2",
"es6-shim": "^0.33.3",

ng2 刚好在 es6 之下,所以你需要 "es6-xxxx"。

我认为这些模块不会占用 90MB 空间,但 NPM 总是在两个模块之间安装一些相同的子模块。不知道这个问题有没有处理(好像没有)。

【讨论】:

  • 我用旧版本的 npm 进行了测试,90MB 大约是教程中列出的所有依赖项的文件大小。
  • 所以问题是你不知道你的程序中是否有相同的子模块。例如,当你使用 koa 和 koa-router 时,它们都会占用co这个模块,两个co模块都会占用空间来存储。
猜你喜欢
  • 1970-01-01
  • 2023-04-01
  • 2016-04-11
  • 2022-01-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-12
相关资源
最近更新 更多