如何在创建NPM包时解决gulp依赖关系

时间:2016-08-05 07:44:05

标签: node.js npm gulp dependencies

我有一个nodeJs应用程序(演示),它使用commander包来获取命令行参数并使用gulp来获取

  1. 构建
  2. 文档
  3. 测试
  4. 覆盖
  5. 此功能正常运行但现在我需要将此应用程序作为 NPM程序包移动。

    根据相应的NPM Package进行更改,但是当我从本地位置将其安装为NPM包npm install ../demo/时。

    它要求遵循gulp依赖: -

    1. 找不到模块gulp
    2. 找不到模块gulp-load-plugins
    3. 找不到模块del
    4. 找不到模块gulp-plumber
    5. 找不到模块gulp-eslint
    6. 找不到模块babel-eslint
    7. 找不到模块gulp-debug
    8. 找不到模块gulp-sourcemaps
    9. 找不到模块gulp-babel
    10. 每次我回到npm包(我创建的)目录并运行命令时出现错误,如npm install gulp --save-devnpm install del --save-dev等等。

      我还在package.json中定义了这些依赖项,但它仍然会抛出错误。

      有没有办法解决这个问题。

      package.json

      {
        "name": "demo",
        "version": "0.0.1",
        "description": "",
        "main": "./dist/index.js",
        "license": "SEE LICENSE IN LICENSE.md",
        "keywords": [],
        "scripts": {
          "build": "gulp build",
          "coverage": "gulp coverage",
          "docs": "gulp docs",
          "prepublish": "gulp build",
          "test": "gulp test"
        },
        "dependencies": {
          "autobind-decorator": "^1.3.3",
          "babel-polyfill": "^6.6.1",
          "commander": "^2.9.0",
          "lodash": "^4.0.0",
          "mustache": "^2.2.1",
          "source-map-support": "^0.4.0",
          "wrench": "^1.5.8",
          "ms": "^0.7.1"
          "babel-eslint": "^6.0.4",
          "babel-plugin-lodash": "^2.2.1",
          "babel-plugin-transform-decorators-legacy": "^1.3.4",
          "babel-preset-nodejs-lts": "^1.2.2",
          "chai": "^3.5.0",
          "del": "^2.2.0",
          "esdoc-es7-plugin": "^0.0.3",
          "gulp": "^3.9.1",
          "gulp-babel": "^6.1.2",
          "gulp-babel-istanbul": "^1.1.0",
          "gulp-debug": "^2.1.2",
          "gulp-esdoc": "^0.2.0",
          "gulp-eslint": "^2.0.0",
          "gulp-filter": "^4.0.0",
          "gulp-inject-modules": "^0.1.1",
          "gulp-load-plugins": "^1.2.2",
          "gulp-mocha": "^2.2.0",
          "gulp-plumber": "^1.1.0",
          "gulp-sourcemaps": "^2.0.0-alpha",
          "sinon": "^1.17.4",
          "sinon-chai": "^2.8.0",
          "btoa": "^1.1.2",
          "superagent": "^2.1.0"
        },
        "engines": {
          "node": ">=4.0.0"
        }
      }
      

      我将所有内容都放在dependencies中。我试过这种方式,但有同样的问题。

      npm install ../demo/
      npm WARN package.json demo_project@1.0.0 No description
      npm WARN package.json demo_project@1.0.0 No repository field.
      npm WARN package.json demo_project@1.0.0 No README data
      
      > demo@0.0.1 prepublish /work/demo
      > gulp build
      
      [16:53:33] Local gulp not found in ~/work/demo
      [16:53:33] Try running: npm install gulp
      

1 个答案:

答案 0 :(得分:1)

虽然documentation没有提及,npm install folder只安装dependencies而不是devDependencies。这可能有点令人困惑,因为在包文件夹中运行npm install会安装 dependenciesdevDependencies

因此,请尝试安装gulp,其余部分安装为npm install --save gulp(不是 --save-dev

添加package.json

更新

devDependenciespackage.json下的所有内容都应位于dependencies下:

{
  "name": "demo",
  "version": "0.0.1",
  "description": "",
  "main": "./dist/index.js",
  "license": "SEE LICENSE IN LICENSE.md",
  "keywords": [],
  "scripts": {
    "build": "gulp build",
    "coverage": "gulp coverage",
    "docs": "gulp docs",
    "prepublish": "gulp build",
    "test": "gulp test"
  },
  "dependencies": {
    "autobind-decorator": "^1.3.3",
    "babel-polyfill": "^6.6.1",
    "commander": "^2.9.0",
    "lodash": "^4.0.0",
    "mustache": "^2.2.1",
    "source-map-support": "^0.4.0",
    "wrench": "^1.5.8",
    "ms": "^0.7.1",
    "babel-eslint": "^6.0.4",
    "babel-plugin-lodash": "^2.2.1",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-preset-nodejs-lts": "^1.2.2",
    "chai": "^3.5.0",
    "del": "^2.2.0",
    "esdoc-es7-plugin": "^0.0.3",
    "gulp": "^3.9.1",
    "gulp-babel": "^6.1.2",
    "gulp-babel-istanbul": "^1.1.0",
    "gulp-debug": "^2.1.2",
    "gulp-esdoc": "^0.2.0",
    "gulp-eslint": "^2.0.0",
    "gulp-filter": "^4.0.0",
    "gulp-inject-modules": "^0.1.1",
    "gulp-load-plugins": "^1.2.2",
    "gulp-mocha": "^2.2.0",
    "gulp-plumber": "^1.1.0",
    "gulp-sourcemaps": "^2.0.0-alpha",
    "sinon": "^1.17.4",
    "sinon-chai": "^2.8.0",
    "btoa": "^1.1.2",
    "superagent": "^2.1.0"
  },
  "engines": {
    "node": ">=4.0.0"
  }
}