![](/img/trans.png)
[英]YARN/NPM: installing package versions that are compatible to certain dependency version
[英]Error installing package using npm instead of yarn
我已經創建了 git 存儲庫,它將在其他項目中用作 npm 包。 假設可共享的存儲庫名稱是genesis-service-broker 。
我在其中一項服務(激活服務)中使用了這個可共享的存儲庫。 在這個項目中,我使用yarn安裝包。 它在這里運行得非常好。
"dependencies": {
...
"genesis-service-broker": "git+https://${key}:x-oauth-basic@git.my_project.com/${user}/genesis-service-broker.git#create_service_broker_for_genesis",
...
}
當我嘗試在其他服務(合作伙伴服務)中使用genesis-service-broker包時,它無法安裝依賴項。 在這個項目中,我使用npm安裝依賴項。 如果我使用紗線安裝依賴項,它的工作非常好。
我在npm install命令中沒有收到任何錯誤。 當我使用npm安裝依賴項時,我只是無法在node_modules 中找到genesis-service-broker文件夾。
package.json文件位於genesis-service-broker存儲庫中。 (供參考)
{
"name": "service-broker",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git@git.my_project.com:amol.barewar/service-broker.git"
},
"author": "",
"license": "ISC",
"dependencies": {
"config": "^3.2.5",
"form-data": "^3.0.0",
"node-fetch": "^2.6.0",
"request": "^2.88.0",
"uuid": "^3.4.0"
}
}
在這里, yarn
和npm
之間的行為有所不同
yarn add
在dependencies 中保留了git項目的名稱,並在node_modules 中創建了一個同名文件夾。
因此, yarn add git+https://${key}:x-oauth-basic@git.my_project.com/${user}/genesis-service-broker.git#create_service_broker_for_genesis
將導致模塊安裝為node_modules /創世服務經紀人
另一方面, npm install
從 package.json 中的name
屬性獲取名稱; 它會導致模塊被添加為node_modules/service-broker在你的情況下......而且依賴關系映射也會像
"dependencies": {
...
"service-broker": "git+https://${key}:x-oauth-basic@git.my_project.com/${user}/genesis-service-broker.git#create_service_broker_for_genesis",
...
}
由於這種差異, requires(...)
可能會失敗。
因為,在這種情況下,使用紗線,該模塊將通過 -
require('genesis-service-broker')
對於npm通過 -
require('service-broker')
因此,總而言之,將 package.json 中的name屬性與項目名稱保持相同會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.