Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot build publishable & buildable library with sub-entries unless using dist path #3417

Closed
nadavsinai opened this issue Jul 27, 2020 · 10 comments

Comments

@nadavsinai
Copy link
Contributor

nadavsinai commented Jul 27, 2020

Current Behavior

Unless directing tsconfig path to dist folder, some of my workspace libraries fail to compile
with out of rootDir error.

for example when compiling our lib sticky-notes with it's tsconfig.json extending your regular tsconfig.base.json
in which it could find '@algotec/ui-elements-webkit/' pointing to ["libs/ui-elements/"]
I get errors like these:

libs/sticky-notes/src/sticky-notes.module.ts:24:30 - error TS6059: File 'F:/client-workspace-2/li
bs/ui-elements-webkit/dropdown/index.ts' is not under 'rootDir' 'F:\client-workspace-2\libs\stick
y-notes\src'. 'rootDir' is expected to contain all source files.

If I change to extend an alternative tsconfig.lib.json which changes all the paths to dist/libs/ the library can compile, but I have to get the compilation order right.

what's confusing is that I found that some libraries that have secondary entry points and relay on libs with secondary entry points do work, I am yet to find an explanation for that.
this issue is probably related to #2794 @juristr I'd love your help debugging this.

Expected Behavior

Compile buildable & publishable libraries also when they have secondary entry points

Steps to Reproduce

I did try to create a new workspace only for reproduction of this error and didn't succeed yet.
I will update here and point a link whenever I make it.

Environment

  @nrwl/angular : 10.0.6
  @nrwl/cli : 10.0.6
  @nrwl/cypress : 10.0.6
  @nrwl/eslint-plugin-nx : Not Found
  @nrwl/express : Not Found
  @nrwl/jest : 10.0.6
  @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 : 10.0.6
  @nrwl/web : Not Found
  @nrwl/workspace : 10.0.6
  typescript : 3.9.7

@juristr
Copy link
Member

juristr commented Jul 27, 2020

hey @nadavsinai...weird 🤔 . Can you provide a sample repo where I could reproduce the build issue?

@juristr juristr added scope: core core nx functionality blocked: repro needed labels Aug 1, 2020
@ganeshpms
Copy link

ganeshpms commented Aug 13, 2020

Try adding paths to the subfolders in tsconfig.base.json, dist path may require you delete the dist to build from source, and make sure you keep your ng-package.json, and package.json under 'src/lib'

      "@scope/library/entry1": ["libs/library/src/lib/entry1/index.ts"],
      "@scope/library/entry2": ["libs/library/src/lib/entry2/index.ts"]

instead of

 "@scope/library/*": ["dist/library/*" , "libs/library/*"],

@nadavsinai
Copy link
Contributor Author

HI @ganeshpms , thanks for your reply. This is not so feasible for us.
For example under ui-elements-webkit (ui components package) we currently have 74 subpackages, moreover putting each sub-package in the global tsconfig is another manual step developers need to do to create a new subpackage - which something we want to encourage not hinder.
I would try this only for testing and report back.
aswell, I am still trying to find the time to create a reproduction repo (same config omitting our code )

@ganeshpms
Copy link

HI @ganeshpms , thanks for your reply. This is not so feasible for us.
For example under ui-elements-webkit (ui components package) we currently have 74 subpackages, moreover putting each sub-package in the global tsconfig is another manual step developers need to do to create a new subpackage - which something we want to encourage not hinder.
I would try this only for testing and report back.
aswell, I am still trying to find the time to create a reproduction repo (same config omitting our code )

@ganeshpms
Copy link

ganeshpms commented Aug 17, 2020

ah, I see your point, we will also hit the same issue soon. I just tried as following after your reply, it works with just two paths. It works also with another publishable library which has reference to this library.

"@scope/library": ["libs/library"],  // <--- Publishable used by @nrwl/angular:package
"@scope/library/*": ["libs/library/src/lib/*"], //<-- Buildable used by @angular-devkit/build-angular:browser and editor (vscode)

to make it work, I just made sure the publishable build the components library as following, instead of the default src/lib/entry1

------------------------------------------------------------------------------
Building entry point '@scope/library/entry1'
------------------------------------------------------------------------------

by keeping the ng-package.json , package.json inside src/lib and angular.json

      "root": "libs/library/src/lib",
      .
      "architect": {
        "build": {
          "builder": "@nrwl/angular:package",
          "options": {
            "tsConfig": "libs/library/tsconfig.lib.json",
            "project": "libs/library/src/lib/ng-package.json"

@nadavsinai
Copy link
Contributor Author

nadavsinai commented Aug 18, 2020

I did test it with the 74 direct references to the subpackages in the paths object and it did not work.
I must be missing on something here
my library has a root of /libs/library
and the project (ng-package.json) and tsconfig properties of the builder options look like this :

	"tsConfig": "libs/library/tsconfig.lib.json",
	"project": "libs/library/ng-package.json"

in addition subpackages exist directly underneath root - not underneath src
eg libs/library/subpackage (with it's own package.json and index.ts)
I don't understand howcome your examples state for library/src/lib (assuming lib is a subpackage name) if src it the location for the main package's code - how will the subpackages code won't be included in the main package in this scenario?

@nadavsinai
Copy link
Contributor Author

I found this was my fault: some of the libraries had another builder - not "@nrwl/angular:package" but our own extended-lib-builder which adds stuff such as assets copying, pre/post build commands and other goodies, but internally it used ng-packager without the special runtime path mapping you're doing in package.imp.js (line 20)
buildable_libs_utils_1.updatePaths(projectDependencies, parsedTSConfig.options.paths);

I changed our own builder to use the run function from @nrwl/angular/src/builders/package/package.impl (pity it isn't exposed from top-level) and now we got the expected behavior

@imcvakt
Copy link

imcvakt commented Aug 19, 2020

Hi, I'm facing the same issue but with react project... Can you provide me more info about the workaround? I know it's closed but...

@HackPoint
Copy link

Hi, I'm facing the same issue but with react project... Can you provide me more info about the workaround? I know it's closed but...

They care more about making features that no one needs instead of fixing the ones that exists.
@vsavkin can you please help ppl with that?

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants