2017-08-17 100 views
2

當運行npm installNPM警告包既包括了開發和生產依賴

我這些警告:

npm WARN The package babel-core is included as both a dev and production dependency. 
npm WARN The package babel-loader is included as both a dev and production dependency. 
npm WARN The package babel-preset-react is included as both a dev and production dependency. 
npm WARN The package redux-thunk is included as both a dev and production dependency. 
npm WARN The package uglifyjs is included as both a dev and production dependency. 

up to date in 7.183s 
npm WARN The package babel-core is included as both a dev and production dependency. 
npm WARN The package babel-loader is included as both a dev and production dependency. 
npm WARN The package babel-preset-react is included as both a dev and production dependency. 
npm WARN The package redux-thunk is included as both a dev and production dependency. 
npm WARN The package uglifyjs is included as both a dev and production dependency. 

package.json文件:

{ 
... 
    "dependencies": { 
    "axios": "^0.15.3", 
    "babel-core": "^6.10.4", 
    "babel-loader": "^6.2.4", 
    "babel-polyfill": "^6.9.1", 
    "babel-preset-es2015": "^6.9.0", 
    "babel-preset-react": "^6.11.1", 
    "babel-preset-stage-2": "^6.24.1", 
    "babel-register": "^6.9.0", 
    "bluebird": "^3.5.0", 
    "bootstrap-sass": "^3.3.7", 
    "classnames": "^2.2.5", 
    "console-polyfill": "^0.2.3", 
    "cross-env": "^1.0.8", 
    "css-loader": "^0.23.1", 
    "deepmerge": "^1.3.2", 
    "dom-helpers": "^3.0.0", 
    "expect": "^1.20.1", 
    "fuzzy": "^0.1.3", 
    "moment": "^2.18.1", 
    "node-libs-browser": "^1.0.0", 
    "node-sass": "^3.8.0", 
    "react": "^15.1.0", 
    "react-addons-shallow-compare": "15.4.0", 
    "react-addons-test-utils": "^15.1.0", 
    "react-axios": "0.0.9", 
    "react-bootstrap-daterangepicker": "^3.2.2", 
    "react-daterange-picker": "^1.1.0", 
    "react-dom": "^15.1.0", 
    "react-draggable": "^2.2.3", 
    "react-redux": "^4.4.8", 
    "react-router": "^3.0.2", 
    "react-virtualized": "^8.5.2", 
    "redux": "^3.6.0", 
    "redux-logger": "^2.6.1", 
    "redux-promise": "^0.5.3", 
    "redux-promise-middleware": "^4.2.0", 
    "redux-thunk": "^2.1.0", 
    "sass-loader": "^4.0.0", 
    "style-loader": "^0.13.1", 
    "uglifyjs": "=2.4.10", 
    "webpack-dev-middleware": "^1.6.1", 
    "webpack-dev-server": "^1.14.1", 
    "webpack-hot-middleware": "^2.11.0" 
    }, 
    "devDependencies": { 
    "assets-webpack-plugin": "^3.5.1", 
    "babel-core": "^6.24.1", 
    "babel-loader": "^7.0.0", 
    "babel-plugin-add-module-exports": "^0.2.1", 
    "babel-plugin-react-transform": "^2.0.2", 
    "babel-plugin-transform-decorators-legacy": "^1.3.4", 
    "babel-preset-es2016": "^6.24.1", 
    "babel-preset-react": "^6.24.1", 
    "babel-preset-stage-3": "^6.24.1", 
    "didyoumean": "^1.2.1", 
    "extract-text-webpack-plugin": "^1.0.1", 
    "glob": "^7.1.1", 
    "postcss-loader": "^1.3.0", 
    "purifycss-webpack-plugin": "^2.0.3", 
    "react-transform-hmr": "^1.0.4", 
    "redux-thunk": "^2.2.0", 
    "uglifyjs": "=2.4.10", 
    "webpack": "^1.15.0", 
    "webpack-cleanup-plugin": "^0.5.1", 
    "webpack-split-chunks": "^0.1.1" 
    } 
} 

注意到有不同版本已安裝。在爲dev和prod安裝相同軟件包的兩個版本時會發生什麼?這是正常的行爲嗎?我應該擺脫package.json文件中的僞造引用嗎?

+0

正如警告試圖告訴你,你不應該那樣做。你應該找出你想要的版本。 – SLaks

+0

它使用什麼版本呢? –

+0

無論你最後安裝哪一個。 – SLaks

回答

5

您已經在您的依賴關係的兩個部分中引用了該包;你完全不應該這樣做,因爲這意味着你的生產安裝將具有與開發安裝不同的版本。

如果你做npm install你會得到所有dependencies & devDependencies安裝;但是,如果您執行npm install --production,則只能安裝dependencies

你應該刪除你不需要的應用程序從dependencies運行並將它們放在devDependencies中。應該將dependencies中的東西視爲運行應用程序的要求(發生任何代碼轉換後)。

在兩種情況下都存在零依賴關係的情況。