首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >npm安装如何防止嵌套的node_mocules文件夹

npm安装如何防止嵌套的node_mocules文件夹
EN

Stack Overflow用户
提问于 2019-04-02 17:40:37
回答 1查看 218关注 0票数 0

我有一个package.json文件,其中包含

代码语言:javascript
复制
"dependencies": {
 "packageA": "^1.0.0",

这个package A在他的package.json中还有另一个依赖项

代码语言:javascript
复制
"dependencies": {
 "packageA_B": "^1.0.0",

然后,如果我在windows 10上运行npm installnode v11.11.0最终会得到

代码语言:javascript
复制
/node_modules/packageA
/node_modules/packageA/node_modules/packageA_B

然后,如果我删除这个包并运行npm install packageA,我最终会得到

代码语言:javascript
复制
/node_modules/packageA
/node_modules/packageA_B

这是我从一开始就想要的。为什么会发生这种不一致的情况?如何强制以非嵌套的方式安装所有包?

代码语言:javascript
复制
package.json

{
  "name": "first_package",
  "private": true,
  "description": "",
  "main": "gatsby-config.js",
  "version": "0.2.25",
  "author": "",
  "dependencies": {
    "packageA": "git+https://blah.git#h5c8f72",

    "gatsby": "2.1.4",
    "gatsby-plugin-compile-es6-packages": "^1.0.6",
    "gatsby-plugin-offline": "^2.0.24",
    "gatsby-plugin-page-creator": "^2.0.10",
    "gatsby-plugin-react-helmet": "^3.0.8",
    "gatsby-plugin-sharp": "^2.0.25",
    "gatsby-plugin-styled-components": "^3.0.6",
    "gatsby-source-filesystem": "^2.0.23",
    "gatsby-transformer-sharp": "^2.1.15",

    "path": "0.12.7",
    "react": "16.8.6",
    "react-dom": "16.8.6",
    "styled-components": "^4.1.3",
    "styled-icons": "^7.4.2"
  },
  "devDependencies": {
    "babel-eslint": "^10.0",
    "eslint": "^5.16.0",
    "eslint-config-prettier": "^4.1.0",
    "eslint-config-standard": "^12.0.0",
    "eslint-plugin-import": "^2.16.0",
    "eslint-plugin-node": "^8.0.1",
    "eslint-plugin-prettier": "^3.0.1",
    "eslint-plugin-promise": "^4.1.1",
    "eslint-plugin-react": "^7.12.4",
    "eslint-plugin-standard": "^4.0.0",
    "gulp": "^4.0.0",
    "gulp-help": "^1.6.1",
    "prettier": "^1.16.4"
  },
  "keywords": [
    ""
  ],
  "license": "",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "test": "echo \"Write tests! -> https://gatsby.app/unit-testing\""
  },
  "repository": {
    "type": "git",
    "url": "https://"
  },
  "bugs": {
    "url": "https://"
  }
}
代码语言:javascript
复制
Package A package.json

{
  "name": "packageA",
  "private": true,
  "description": "",
  "version": "0.2.25",
  "main": "index.js",
  "author": "",
  "dependencies": {
    "packageA_B": "0.2.25",

    "styled-components": "4.2.0",
    "styled-icons": "7.9.0",
    "babel-plugin-styled-components": "1.10.0",
    "gatsby-plugin-styled-components": "3.0.7",

    "gatsby-plugin-page-creator": "2.0.12",
    "gatsby-source-filesystem": "2.0.28",
    "gatsby-plugin-compile-es6-packages": "1.1.0",
    "path": "0.12.7",
    "esm": "3.2.14",
    "prop-types": "15.7.2",

    "gatsby-plugin-gtag": "1.0.10",
    "gatsby-plugin-manifest": "2.0.26",
    "react-cookie-consent": "2.2.2"
  },
  "peerDependencies": {
    "gatsby": "2.1.4",
    "react": "16.8.6",
    "react-dom": "16.8.6"
  },
  "devDependencies": {
    "gatsby": "2.1.4",
    "react": "16.8.6",
    "react-dom": "16.8.6",

    "babel-eslint": "^10.0",
    "eslint": "^5.16.0",
    "eslint-config-prettier": "^4.1.0",
    "eslint-config-standard": "^12.0.0",
    "eslint-plugin-import": "^2.16.0",
    "eslint-plugin-node": "^8.0.1",
    "eslint-plugin-prettier": "^3.0.1",
    "eslint-plugin-promise": "^4.1.1",
    "eslint-plugin-react": "^7.12.4",
    "eslint-plugin-standard": "^4.0.0",
    "gulp": "^4.0.0",
    "gulp-help": "^1.6.1",
    "prettier": "^1.16.4"
  },
  "keywords": [
    ""
  ],
  "license": "",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "test": "echo \"Write tests! -> https://gatsby.app/unit-testing\""
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "bugs": {
    "url": ""
  }
}
代码语言:javascript
复制
Package A_B package.json

{
  "name": "packageA_B",
  "version": "0.2.25",
  "description": "",
  "author": "",
  "main": "index.js",
  "license": "",
  "private": false,
  "dependencies": {
    "styled-components": "4.2.0",
    "styled-icons": "7.9.0",
    "babel-plugin-styled-components": "1.10.0",
    "gatsby-plugin-styled-components": "3.0.7",

    "gatsby-plugin-page-creator": "2.0.12",
    "gatsby-source-filesystem": "2.0.28",
    "gatsby-plugin-compile-es6-packages": "1.1.0",
    "path": "0.12.7",
    "esm": "3.2.14",
    "prop-types": "15.7.2",

    "gatsby-mdx": "0.4.2",
    "@mdx-js/mdx": "0.20.3",
    "@mdx-js/tag": "0.20.3",
    "gatsby-image": "2.0.31",
    "gatsby-plugin-offline": "2.0.25",
    "gatsby-plugin-react-helmet": "3.0.11",
    "gatsby-plugin-sharp": "2.0.32",
    "gatsby-transformer-sharp": "2.1.17",
    "react-helmet": "5.2.0",
    "react-share": "2.4.0"
  },
  "peerDependencies": {
    "gatsby": "2.1.4",
    "react": "16.8.6",
    "react-dom": "16.8.6"
  },
  "devDependencies": {
    "gatsby": "2.1.4",
    "react": "16.8.6",
    "react-dom": "16.8.6",

    "babel-eslint": "^10.0",
    "eslint": "^5.16.0",
    "eslint-config-prettier": "^4.1.0",
    "eslint-config-standard": "^12.0.0",
    "eslint-plugin-import": "^2.16.0",
    "eslint-plugin-node": "^8.0.1",
    "eslint-plugin-prettier": "^3.0.1",
    "eslint-plugin-promise": "^4.1.1",
    "eslint-plugin-react": "^7.12.4",
    "eslint-plugin-standard": "^4.0.0",
    "gulp": "^4.0.0",
    "gulp-help": "^1.6.1",
    "prettier": "^1.16.4"
  },
  "keywords": [
    ""
  ],
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "test": "echo \"Write tests! -> https://gatsby.app/unit-testing\""
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "bugs": {
    "url": ""
  }
}
EN

回答 1

Stack Overflow用户

发布于 2019-04-03 14:39:42

通过指定兼容的版本"^1.0.0"而不是精确的版本"1.0.0"来解决。不知何故,对于确切的版本,npm并不共享这个包,即使它们是完全相同的版本。此外,如果指定了确切的版本,则运行npm dedupe不会产生任何影响。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55471546

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档