【问题标题】:How to use global/common node_modules instead of local node_modules?如何使用全局/通用 node_modules 而不是本地 node_modules?
【发布时间】:2018-05-08 04:08:23
【问题描述】:

我想使用 global node_modules (C:\Users\<user_name>\AppData\Roaming\npm\node_modules) 或 common node_modules (D:\node_modules) 而不是本地 node_modules (D:\angular\projects\project1\node_modules)。

我想将 node_modules 用于各种项目。

这是我的项目结构。 D:\ ├── node_modules (common for all projects) │ ├── Module-N ├── projects │ ├── project1 │ │ ├── src │ │ ├── app │ │ | ├── Module-N (importing from common) | │ ├── project2 │ │ ├── src │ │ ├── app │ │ | ├── Module-N (importing from common) | ├── ....

【问题讨论】:

    标签: node.js angular global node-modules


    【解决方案1】:

    尝试使用相对路径,例如当您需要自己的全局模型模块时

    例如

    假设我们想从全局节点模块中获取一个模块,并且我们正在处理的文件是 projects/project1/src 上的席位

    我们会做require('../../../node_modules/my_global_model')

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 当我使用 Angular cli (ng serve/build) 启动 Angular 应用程序 (project1) 时,我得到了以下信息。ENOENT: no such file or directory, lstat 'D:\Angular\Project1\node_modules
      猜你喜欢
      • 2020-11-19
      • 2015-09-09
      • 1970-01-01
      • 2023-01-22
      • 2012-05-15
      • 2011-11-07
      • 2020-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多