然后你可以像往常一样要求你的 libB 代码:const libB = require('libB')I have the following folder structure:~ (user home folder) - api ... - package.json - lib - libA ... package.json - libB ... package.jsonIn libA/package.json I have the following local dependency"dependencies": { "libB": "../libB", },So libA depends on libB.Now I want inside api project to add as local package libA. I execute cd api && yarn add ../lib/libA and I get the following error/Users/a_user/libB doesn't exist. I understand that yarn sees as current director ~/api so when is reading the dependency of libA it sees ../libB and translate it as ~/libB and not as ~/lib/libBIs there anyway to achieve it without absolute paths ? 解决方案 Yes, there is, using yarn link. Basically, yarn link allows you to create symlinks to local projects.Go to the folder libB and run:yarn linkThen go to the folder libA and run:yarn link libBNOTE: that libB must be the name on the package.json inside the libB folderThen you can require your libB code as usual:const libB = require('libB') 这篇关于纱线本地包依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 阿里云证书,YYDS!
05-22 01:57