Cannot build library which depends on publishable lib in sub folder
See original GitHub issueExpected Behavior
It should be possible to build a publishable lib that depends on another publishable lib that resides in a sub folder.
Current Behavior
The issue I have is similar to https://github.com/nrwl/nx/issues/602 which is already fixed and working. However, if I have my libs in sub folders (e.g. libs/platform/my-lib) then it still fails with 'rootDir' is expected to contain all source files.
Failure Information (for bugs)
Steps to Reproduce
- I created a new nx angular workspace and added 2 publishable libs in the directory ‘platform’.
yarn create nx-workspace
nx g lib core --directory platform --publishable --simple-module-name
nx g lib common --directory platform --publishable --simple-module-name
- Created 1 class in each lib. The class in
common
uses the one fromcore
like so:
import { Foo } from '@my-org/platform-core';
export class Bar {
public run(): void {
new Foo().run();
}
}
- In addition I modified the
tsconfig.json
on root level from
"@my-org/platform/core": ["libs/platform/core/src/index.ts"],
"@my-org/platform/common": ["libs/platform/common/src/index.ts"]
to
"@my-org/platform-core": ["libs/platform/core/src/index.ts"],
"@my-org/platform-common": ["libs/platform/common/src/index.ts"]
(not sure why its created like this although in the package.json
the libs are named “@my-org/platform-core” and “@my-org/platform-common”)
However, it does not make any difference. So even if I keep it like @my-org/platform/core
(in tsconfig.json and the import in the class in common
lib) the error is the same.
- Then run
nx build platform-core
(works!)nx build platform-common
(fails)
See also: https://github.com/mrucelum/nx_publishable_lib
Context
@nrwl/angular : 9.2.1 @nrwl/cli : 9.2.1 @nrwl/cypress : 9.2.1 @nrwl/eslint-plugin-nx : Not Found @nrwl/express : Not Found @nrwl/jest : 9.2.1 @nrwl/linter : Not Found @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : Not Found @nrwl/react : Not Found @nrwl/schematics : Not Found @nrwl/tao : 9.2.1 @nrwl/web : Not Found @nrwl/workspace : 9.2.1 typescript : 3.8.3
Failure Logs
Compiling TypeScript sources through ngc
ERROR: libs/platform/core/src/index.ts:1:15 - error TS6059: File '~/nx_publishable_lib/libs/platform/core/src/lib/foo.ts' is not under 'rootDir' '~\nx_publishable_lib\libs\platform\common\src'. 'rootDir' is expected to contain all source files.
1 export * from './lib/foo';
~~~~~~~~~~~
libs/platform/common/src/lib/bar.ts:1:21 - error TS6059: File '~/nx_publishable_lib/libs/platform/core/src/index.ts' is not under 'rootDir' '~\nx_publishable_lib\libs\platform\common\src'. 'rootDir' is expected to contain all source files.
1 import { Foo } from '@my-org/platform-core';
~~~~~~~~~~~~~~~~~~~~~~~
An unhandled exception occurred: libs/platform/core/src/index.ts:1:15 - error TS6059: File '~/nx_publishable_lib/libs/platform/core/src/lib/foo.ts' is not under 'rootDir' '~\nx_publishable_lib\libs\platform\common\src'. 'rootDir' is expected to contain all source files.
1 export * from './lib/foo';
~~~~~~~~~~~
libs/platform/common/src/lib/bar.ts:1:21 - error TS6059: File '~/nx_publishable_lib/libs/platform/core/src/index.ts' is not under 'rootDir' '~\nx_publishable_lib\libs\platform\common\src'. 'rootDir' is expected to contain all source files.
1 import { Foo } from '@my-org/platform-core';
Issue Analytics
- State:
- Created 3 years ago
- Reactions:22
- Comments:33 (11 by maintainers)
Same here. It prevents me from using incremental compilation with:
nx build my-app --with-deps
.Is there a solution on the horizon?
Hey all, sorry for the long wait 😞 .
So we basically just merged #2840 and it should have been already released with v10.0.3. Just upgrading won’t work as we didn’t do any migration because that would have been difficult & probably suboptimal.
So what changed?
So what did I add in the PR. Basically we’re currently trying to optimize the incremental build story & the PR is a first step in that direction. So the PR now clearly distinguishes between
--publishable
and--buildable
. While they were aliases before, now there’s a difference.--publishable
now requires you to pass in a required--importPath
param, which should be the npm name you plan to use when releasing the package (e.g.@myorg/my-awesome-package
or simplymy-awesome-package
). We require that--importPath
explicitly as we didn’t want to do any guesswork here. ThatimportPath
is what the TSConfig path mappings will use & what will be in yourpackage.json
--buildable
instead doesn’t do any TSConfig path manipulation or require any additional work. It is basically kind of the--publishable
from Nxv9
. Why would you need abuildable
library? For incremental building. See our docs for more info and an example repo.How can I fix my workspace?
The best is to generate a new Nx v10 workspace, create a similar scenario you’re having in your app & have a look at the differences. It should mostly be the TSConfig path mappings & package.json names.
If you have questions, or if there are still issues, please let me/us know and open a new issue 😃