【问题标题】:Install node_module from npm but it doesn't install its own node_modules - package.json从 npm 安装 node_module 但它没有安装自己的 node_modules - package.json
【发布时间】:2014-02-08 00:27:57
【问题描述】:

我刚刚创建了一个带有“验证器”依赖项的 node_module。 但是当我从 npm 安装它时,它不会在自己的 node_module 目录中安装“验证器”模块。我不明白为什么,但这是我第一次创建自己的节点模块。

package.json:

{
  "name": "validator-extended",
  "description": "String validation and sanitization based on validator.js",
  "version": "1.1.0",
  "homepage": "https://github.com/Ayolan/validator-extended",
  "keywords": [
    "validator",
    "validation",
    "validate",
    "sanitization",
    "sanitize",
    "sanitisation",
    "sanitise",
    "assert",
    "extend",
    "extended"
  ],
  "author": "Vadorequest <https://github.com/Vadorequest>",
  "main": "app.js",
  "bugs": {
    "url": "https://github.com/Ayolan/validator-extended/issues"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/Ayolan/validator-extended.git"
  },
  "engines": {
    "node": ">= 0.8"
  },
  "licenses": [
    {
      "type": "MIT",
      "url": "https://github.com/Ayolan/validator-extended/raw/master/LICENSE"
    }
  ],
  "dependencies": {
    "validator": "~3.1"
  }
}

我还有一个 .npmignore 文件:

########################
# node.js / npm
########################
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

node_modules

npm-debug.log


########################
# misc / editors
########################
*~
*#
.DS_STORE
.netbeans
nbproject
.idea

我应该将 node_modules/ 目录推送到我的 git 存储库中吗?

【问题讨论】:

    标签: node.js dependencies node-modules


    【解决方案1】:

    您应该删除现有的package.json 并运行

    npm init
    

    正确初始化您的项目。完成后,将验证器添加到依赖项。这应该允许npm install 正常工作并安装您的依赖项。不要提交您的 node_modules 文件夹。

    【讨论】:

    • 我刚刚做到了。我还更新了主帖,以展示我在 npm init 之前的旧 package.json 的情况。
    • 如果之前的 package.json 是导致问题的原因,您应该在问题中恢复它。这样其他有同样问题的人就能认出来。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-03
    • 1970-01-01
    • 2017-06-05
    • 2016-03-14
    • 1970-01-01
    • 2016-11-23
    • 2013-02-15
    相关资源
    最近更新 更多