简体   繁体   English

纱线安装 package 从 npm 而不是工作区

[英]Yarn install package from npm and not workspace

I'm encountering a problem with yarn workspaces, here is my situation:我遇到了纱线工作区的问题,这是我的情况:

I have a monorepo that contains:我有一个包含:

  • a packages folder containing npm packages包含 npm 个包的包文件夹
  • an apps folder containing nodejs apps包含 nodejs 应用程序的应用程序文件夹

In one of my apps, I'm trying to install a package from my packages folder that is published in npm, but when I do yarn install , it keeps using the workspace folder and doesn't download the npm package nor updates the yarn lock.在我的一个应用程序中,我试图从 npm 中发布的包文件夹中安装 package,但是当我执行yarn install时,它会继续使用工作区文件夹并且不会下载 npm package 也不会更新 yarn 锁.

How can I tell yarn to not use the workspace folder for install but download it from the remote?我怎样才能告诉 yarn 不要使用工作区文件夹进行安装,而是从远程下载它? I'm using the workspaces only for local builds.我仅将工作区用于本地构建。

If you are using yarn berry, it looks up the package in your workspace first and remote registry after.如果您使用的是 yarn berry,它会先在您的工作区中查找 package,然后再查找远程注册表。 This behavior can be changed by setting enableTransparentWorkspaces: false in your .yarnrc.yml file at root.可以通过在根目录下的.yarnrc.yml文件中设置enableTransparentWorkspaces: false来更改此行为。

// .yarnrc.yml

enableTransparentWorkspaces: false
...

If you want to get a package from your workspace with the above option is set, you should explicitly add workspace: protocol as a prefix for your package name in your package.json .如果您想从设置了上述选项的工作区中获取 package,您应该在 package.json 中明确添加workspace: protocol 作为package.json名称的前缀。

"my-package": "workspace:^2.0.17",

See more at:更多信息请访问:

if it is yarn 2+ (berry) you can use npm protocol如果是纱线 2+(浆果),您可以使用npm 协议

but I have some issue with it但我有一些问题

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

相关问题 运行“npm install”,就好像包不在工作区中一样 - Run "npm install" as if package was not in workspace Yarn 在工作区中安装单个包的生产依赖项 - Yarn install production dependencies of a single package in workspace 如何使用 yarn 安装私有 npm 包? - How to install private npm package with yarn? NPM 7 工作区 - 如何在工作区中安装新的 package? - NPM 7 workspaces - how to install new package in workspace? 在 NPM 之后安装 Yarn - Install Yarn after NPM 如何在 Yarn 中从 github repo 安装 package - How to install package from github repo in Yarn 在尝试安装新的NPM软件包时,请在PhpStorm / WebStorm中指定“npm或yarn package” - “Please specify npm or yarn package” in PhpStorm/WebStorm when trying to install a new NPM package 如何在不使用npm install的情况下安装/下载软件包 <package_name> 或纱线安装 - How to install/download packages without using npm install <package_name> or yarn install 在将node-gyp标志传递给包时,yarn添加包--build-from-source的行为类似于npm安装包--build-from-source吗? - Does yarn add package --build-from-source behave like npm install package --build-from-source when passing node-gyp flags to packages? 如何通过使用npm install或yarn安装仅具有自己版本的package.json依赖项 - how to install only package.json dependencies with their own versions by using npm install or yarn
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM