【问题标题】:How to find node-gyp dependency (..or any dependency) in npm project如何在 npm 项目中找到 node-gyp 依赖项(..或任何依赖项)
【发布时间】:2021-12-22 07:47:59
【问题描述】:

我在试图让一个项目运行(即通过调用 'npm install')时遇到了难以想象的挫折,但总是会在 node-gyp 上绊倒。我在 Windows 上,所以我需要安装 python 和 Visual Studio 之类的东西。

长话短说...我不想依赖于像 Visual Studio 那样的一堆腐烂的 s***,所以我想看看这个 node-gyp 是否可以以某种方式是可选的,或者被摆脱的。

现在,如果我打开我的 package.json 文件,我会找到这些依赖项。

  "devDependencies": {
    "autoprefixer-stylus": "^0.7.1",
    "browser-sync": "^2.8.2",
    "gulp": "^3.9.0",
    "gulp-cache": "^0.3.0",
    "gulp-concat": "^2.6.0",
    "gulp-if": "^1.2.5",
    "gulp-imagemin": "^2.3.0",
    "gulp-minify-html": "^1.0.4",
    "gulp-nunjucks-html": "^1.2.2",
    "gulp-order": "^1.1.1",
    "gulp-plumber": "^1.0.1",
    "gulp-stylus": "^2.0.6",
    "gulp-uglify": "^1.2.0",
    "gulp-util": "^3.0.6",
    "jeet": "^6.1.2",
    "kouto-swiss": "^0.11.13",
    "minimist": "^1.1.3",
    "rupture": "^0.6.1"
  },
  "dependencies": {
    "gulp-install": "^0.6.0"
  }

我可以通过这里查看每个包的依赖树:

http://npm.anvaka.com/#/

但是,如果我遍历这些依赖项中的每一个,我将无法在任何地方看到其中任何一个的 node-gyp 依赖项。

我对依赖项有什么不明白的地方吗?什么使用节点gyp?为什么?

【问题讨论】:

    标签: javascript node.js npm gulp node-gyp


    【解决方案1】:

    本机 C/C++ 插件需要 node-gyp,如文档 here 中所述

    依赖项建立在每个目标平台上。对于 Windows 平台,它需要 installation notes here

    中提到的 Visual Studio

    node-gyp 本身并未在package.json 中提及(可能是因为它需要全局安装)因此,您必须手动查看是否有任何依赖项或其嵌套依赖项正在使用本机 c/c++ 附加组件,或者通过他们的 repo或下载的源代码或 npm 安装日志本身。一种方法是在 npm_modules 文件夹中搜索文件 binding.gyp.cc/.cpp 文件,您应该能够找到罪魁祸首 npm 模块。

    【讨论】:

      【解决方案2】:

      npm ls 列出您项目中的已安装 依赖项。 npm ls node-gyp 会限制 node-gyp 的子树。

      npm-remote-ls 列出远程包的所有依赖项。你手动通过或使用grep

      我创建了findep,它比两者都快得多(为此)。它可以检查你的本地项目、外部 npm 包,甚至是远程 github 项目,并且有一个 --greedy 选项,一旦找到指定的依赖项就会停止。

      # Checks if current project has a 'node-gyp' dependency
      findep node-gyp
      
      # Checks if the npm package 'node-sass' has a 'node-gyp' dependency
      findep node-gyp -e node-sass
      
      # Greedily checks if the project 'AngularClass/angular2-webpack-starter' has at least one of these dependencies including "devDependencies":
      $ findep he mime lodash ms -GDr -e AngularClass/angular2-webpack-starter
      Looking for [he, mime, lodash, ms] in AngularClass/angular2-webpack-starter...
      Found 16 dependencies that use [he, mime, lodash, ms]:
      assets-webpack-plugin > lodash
      string-replace-loader > lodash
      karma-coverage > lodash
      

      【讨论】:

        【解决方案3】:

        找到它的依赖项

        npm ls node-gyp
        

        【讨论】:

          【解决方案4】:

          node-gyp 用于编译 node 的原生插件模块。您是否查看过文档here,尤其是 Windows 信息?另外,请查看 this question 以了解有关 Visual Studio 要求的方法

          【讨论】:

            猜你喜欢
            • 2014-03-04
            • 1970-01-01
            • 2016-02-18
            • 1970-01-01
            • 2015-03-29
            • 1970-01-01
            • 2021-01-21
            • 2020-07-21
            • 1970-01-01
            相关资源
            最近更新 更多