Nx: Can't build publishable lib which depends on other libs

Created on 13 Aug 2020  路  4Comments  路  Source: nrwl/nx

Current Behavior

Trying to build a a publishable lib with other libs as dependencies fail.
NX latest version.
Preset: React

Expected Behavior

I wanna create publishable react libs which has other dependencies (non publishable)

Steps to Reproduce

  1. npx create-nx-workspace@latest
  2. use react template
  3. nx generate @nrwl/react:library --name=a --importPath=a --publishable --no-interactive
  4. nx generate @nrwl/react:library --name=b --no-interactive
  5. import lib b at lib a
  6. nx build b

Failure Logs

image

image

react bug

Most helpful comment

It seems like you'd need to pass --buildable to step 4 and manually add paths yo your publishable library's tsconfig.json

{ "extends": "../../tsconfig.base.json", "compilerOptions": { "jsx": "react", "allowJs": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "paths": { "@test/lib2": ["dist/libs/lib2"] } }, "files": [], "include": [], "references": [ { "path": "./tsconfig.lib.json" }, { "path": "./tsconfig.spec.json" } ] }

All 4 comments

It seems like you'd need to pass --buildable to step 4 and manually add paths yo your publishable library's tsconfig.json

{ "extends": "../../tsconfig.base.json", "compilerOptions": { "jsx": "react", "allowJs": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "paths": { "@test/lib2": ["dist/libs/lib2"] } }, "files": [], "include": [], "references": [ { "path": "./tsconfig.lib.json" }, { "path": "./tsconfig.spec.json" } ] }

Hi there @imcvakt ! Thanks for filing an issue!

Did you try the solution that @MmtBkn provided? I believe it should solve your issue. Let me know if this helps, and I can close this issue!

Hi there @imcvakt ! After talking with some of my colleagues, things cleared a bit.
Right now this is by design. Publishable libs can only depend on other publishable libs.

So, to solve your issue, you can make them both publishable. If you make them both publishable, and then import b into a, then you can run nx build a --with-deps and it will work like a charm (no need to do anything else - no need for any manual editing).

I will close this issue for now, but please reopen if my suggestions did not solve your issue! Thanks again! :)

Sorry for the late response. I will try to check @MmtBkn workaround and I come back with more info... Even after that reply :P @mandarini

Was this page helpful?
0 / 5 - 0 ratings

Related issues

about-code picture about-code  路  3Comments

markphip picture markphip  路  3Comments

joelmuskwe picture joelmuskwe  路  3Comments

olakara picture olakara  路  3Comments

elliotmendiola picture elliotmendiola  路  3Comments