简体   繁体   English

使用 npm 而不是 yarn 安装包时出错

[英]Error installing package using npm instead of yarn

I have created git repository which will be used as npm package in other project.我已经创建了 git 存储库,它将在其他项目中用作 npm 包。 Lets say that sharable repository name is genesis-service-broker .假设可共享的存储库名称是genesis-service-broker

I am using this shareable repository inside one of the service( activation service).我在其中一项服务(激活服务)中使用了这个可共享的存储库。 In this project, I am installing package using yarn .在这个项目中,我使用yarn安装包。 Its running perfectly fine here.它在这里运行得非常好。

    "dependencies": {
        ...
        "genesis-service-broker": "git+https://${key}:x-oauth-basic@git.my_project.com/${user}/genesis-service-broker.git#create_service_broker_for_genesis",
        ...
    }

When I am trying to use genesis-service-broker package inside onother service( partner service) its not able to install the dependencies.当我尝试在其他服务(合作伙伴服务)中使用genesis-service-broker包时,它无法安装依赖项。 In this project, I am installing dependencies using npm .在这个项目中,我使用npm安装依赖项。 If I install dependencies using yarn its working perfectly fine.如果我使用纱线安装依赖项,它的工作非常好。

I am not getting any errors in npm install command.我在npm install命令中没有收到任何错误。 I am just not able to find genesis-service-broker folder inside node_modules , when I am installing dependencies using npm .当我使用npm安装依赖项时,我只是无法在node_modules 中找到genesis-service-broker文件夹。

package.json file inside genesis-service-broker repository. package.json文件位于genesis-service-broker存储库中。 (for reference purposes) (供参考)

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

there is a difference in behaviour here, between yarn and npm在这里, yarnnpm之间的行为有所不同

yarn add retains the name of the git project in dependencies, and creates a folder with the same name in node_modules. yarn add在dependencies 中保留了git项目的名称,并在node_modules 中创建了一个同名文件夹。

So, yarn add git+https://${key}:x-oauth-basic@git.my_project.com/${user}/genesis-service-broker.git#create_service_broker_for_genesis will lead to a module getting installed as node_modules/genesis-service-broker因此, yarn add git+https://${key}:x-oauth-basic@git.my_project.com/${user}/genesis-service-broker.git#create_service_broker_for_genesis将导致模块安装为node_modules /创世服务经纪人

On the other side, npm install gets the name from the name property in package.json;另一方面, npm install从 package.json 中的name属性获取名称; and it will lead to module getting added as node_modules/service-broker in your case... and also the dependencies map will be like它会导致模块被添加为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",
   ...
}

Because of this difference, the requires(...) might fail.由于这种差异, requires(...)可能会失败。

As, in this case, with yarn that module will be available through -因为,在这种情况下,使用纱线,该模块将通过 -

require('genesis-service-broker')

And for npm through -对于npm通过 -

require('service-broker')

So, all in all, it will help to keep the name property in package.json same as the project name.因此,总而言之,将 package.json 中的name属性与项目名称保持相同会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM