- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下问题。目前我想构建一个 NPM 模块,其预期行为:
一旦我安装了它,它的所有依赖项都可以在项目中完美运行,只需导入它们。
首先,我拥有的是:
我有“my-module”项目作为我想要的特定版本的依赖模块。
另一方面,我有一个项目导入它,正如我们所看到的。
在我的项目中,我想编写以下代码并最终运行它:
import {Calendar} from 'primereact/calendar';
我该如何处理这个麻烦?
提前致谢!
编辑:我的项目的 package.json 是这样的
{
"name": "my-project",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "next src",
"build": "next build src",
"start": "next start src"
},
"license": "ISC",
"dependencies": {
"next": "^9.0.3",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"@ascope/my-module": "file://../my-module"
}
}
还有我的模块的 package.json:
{
"name": "my-module",
"version": "0.0.1",
"main": "index.js",
"scripts": {
"test": "exit 1"
},
"license": "ISC",
"bundledDependencies": [
"primereact",
"rxjs"
],
"dependencies": {
"primereact": "^3.1.8",
"rxjs": "^6.5.2"
},
"peerDependencies": {
"primereact": "^3.1.8",
"rxjs": "^6.5.2"
}
}
最佳答案
两个包都需要 primereact
依赖项,当您在顶级包上执行 install
时,它会将 primereact
依赖项向上移动,假设有一个版本可以满足这两个依赖项。
For this package{dep} structure: A{B,C}, B{C}, C{D}, this algorithm produces:
A
+-- B
+-- C
+-- D
<小时/>That is, the dependency from B to C is satisfied by the fact that A already caused C to be installed at a higher level. D is still installed at the top level because nothing conflicts with it.
For A{B,C}, B{C,D@1}, C{D@2}, this algorithm produces:
A
+-- B
+-- C
`-- D@2
+-- D@1
Because B’s D@1 will be installed in the top level, C now has to install D@2 privately for itself. This algorithm is deterministic, but different trees may be produced if two dependencies are requested for installation in a different order.
您还可以运行npm dedupe
关于javascript - 如何从其他 npm 依赖项导入模块依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57361623/
我是一名优秀的程序员,十分优秀!