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

时间:2023-01-19 18:15:28

I have a nodeJs application(demo) which using commander package to take command line argument and using gulp for

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

  1. build
  2. docs
  3. test
  4. coverage

This functionality is working fine but Now I need to move this application as a NPM Package.

此功能工作正常但现在我需要将此应用程序作为NPM包移动。

Changes are done according to according NPM Package but when I install this as NPM package npm install ../demo/ from local location.

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

It asks for following gulp dependencies: -

它要求遵循gulp依赖: -

  1. Cannot find module gulp
  2. 找不到模块gulp

  3. Cannot find module gulp-load-plugins
  4. 找不到模块gulp-load-plugins

  5. Cannot find module del
  6. 找不到模块del

  7. Cannot find module gulp-plumber
  8. 找不到模块gulp-plumber

  9. Cannot find module gulp-eslint
  10. 找不到模块gulp-eslint

  11. Cannot find module babel-eslint
  12. 找不到模块babel-eslint

  13. Cannot find module gulp-debug
  14. 找不到模块gulp-debug

  15. Cannot find module gulp-sourcemaps
  16. 找不到模块gulp-sourcemaps

  17. Cannot find module gulp-babel
  18. 找不到模块gulp-babel

Every time I go back to the npm package(which i created) directory and run the command which occurs as an error like npm install gulp --save-dev and npm install del --save-dev and so on.

每次我回到npm包(我创建的)目录并运行命令,如npm install gulp --save-dev和npm install del --save-dev等错误。

I also defined these dependencies in package.json but it is still throwing errors.

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

Is there any way to resolve this issue.

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

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"
  }
}

I put all the things in dependencies. I tried that way but having same problem.

我把所有的东西都放在依赖中。我试过这种方式,但有同样的问题。

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 个解决方案

#1


1  

Although the documentation doesn't mention it, npm install folder only installs dependencies and not devDependencies. This may be a little bit confusing as running npm install inside the package folder installs both dependenciesand devDependencies.

虽然文档没有提到它,但是npm install文件夹只安装依赖项而不是devDependencies。这可能有点令人困惑,因为在包文件夹中运行npm install会安装依赖项和devDependencies。

So try to install gulpand all the rest as npm install --save gulp (not --save-dev)

所以尝试安装gulpand所有其余的npm install --save gulp(不是--save-dev)


UPDATE: after adding package.json:

更新:添加package.json后:

everything under devDependencies in your package.json should be under dependencies:

package.json中devDependencies下的所有内容都应该在依赖项下:

{
  "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"
  }
}

#1


1  

Although the documentation doesn't mention it, npm install folder only installs dependencies and not devDependencies. This may be a little bit confusing as running npm install inside the package folder installs both dependenciesand devDependencies.

虽然文档没有提到它,但是npm install文件夹只安装依赖项而不是devDependencies。这可能有点令人困惑,因为在包文件夹中运行npm install会安装依赖项和devDependencies。

So try to install gulpand all the rest as npm install --save gulp (not --save-dev)

所以尝试安装gulpand所有其余的npm install --save gulp(不是--save-dev)


UPDATE: after adding package.json:

更新:添加package.json后:

everything under devDependencies in your package.json should be under dependencies:

package.json中devDependencies下的所有内容都应该在依赖项下:

{
  "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"
  }
}