question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ng build v6 does not use paths section of root tsconfig.json

See original GitHub issue

Versions

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 6.0.0-rc.5
Node: 8.11.1
OS: darwin x64
Angular: 6.0.0-rc.5
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.5.7
@angular-devkit/build-angular      0.5.7
@angular-devkit/build-ng-packagr   0.5.7
@angular-devkit/build-optimizer    0.5.7
@angular-devkit/core               0.5.7
@angular-devkit/schematics         0.5.7
@angular/material                  5.2.5
@ngtools/json-schema               1.1.0
@ngtools/webpack                   6.0.0-rc.5
@schematics/angular                0.5.7
@schematics/update                 0.5.7
rxjs                               6.0.0-uncanny-rc.7
typescript                         2.7.2
webpack                            4.5.0

Repro steps

  • Generate a new repository with 2 libraries in projects/*.
  • Library A must import Library B
  • Write and run unit test for Library A
  • run ng build.

Observed behavior

If running ng test, the project resolves /tsconfig.json at per each library’s ./project/libraryA/tsconfig.spec.json. The root tsconfig.json has an automatically managed paths block, linked with the output directories.

Running ng build, it appears that we don’t invoke ng-packagr using that tsconfig.json file, or even resolve the paths block, resulting in a slew of errors of this sort:

projects/libraryA/src/test.model.ts(18,29): error TS2307: Cannot find module 'libraryB'.

Desired behavior

It should be possible to provide a paths block for dependency resolution during the build step.

Mention any other details that might be useful (optional)

I’m working through a full migration on a public project here: https://github.com/kangaroo-server/kangaroo-ui/tree/feature/ng6

Repro steps on that repo:

yarn install --pure-lockfile
yarn build # note that it has import failures on @kangaroo/angular-authn
yarn test angular-authn # This works.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
MarcosMelicommented, Nov 11, 2018

Solved the problem in Angular 7 adding the paths to both tsconfig files

  • paths in tsconfig.json helps vscode to works and with intellisense
  • paths in tsconfig.app.json is also needed for angular

tsconfig.json

image

tsconfig.app.json

image

and the intellisense works great

image

9reactions
aboodzcommented, May 2, 2018

I was trying to create a mono repo project and I stumble upon the same issue. After hours of diagnosing the issue, I reached out the same conclusion @krotscheck mentioned. NgPackagr will overwrite baseUrl to the entry point, which is src/public_api (see line 44).

The workaround is manually adding the path to either tsconfig.json in root, or tsconfig.lib.json in lib. I still find this solution weird since the path ../../../dist/my-library is very very relative.

one more thing

The same thing well happen if you want to reference your lib in another app, you have to add another path relative to the app directory this time not relative to src. Of course this is not related to ng-packagr. Your tsconfig.json will end up something like this:

{
  "compilerOptions": {
    ...,
    "paths": {
      "my-library": [
        "dist/my-library", // mostly for the IDE
        "../../dist/my-library", // for the app
        "../../../dist/my-library" // for another lib
      ]
    }
  }
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use paths in tsconfig.json? - Stack Overflow
Just specify the baseUrl, config will take care of your relative path. way to config: tsconfig.json file add the below properties.
Read more >
Angular compiler options
The ngc command is just a wrapper around TypeScript's tsc compiler command and is primarily configured via the tsconfig.json configuration options documented in ......
Read more >
Complete beginner guide to publishing an Angular library to ...
This post will cover steps right from creating the library to detailed NPM ... The Angular CLI uses the tsconfig paths to tell...
Read more >
Configuration File - Karma
Under the hood Karma uses ts-node to transpile TypeScript to JavaScript. If the resolved tsconfig.json has module configured as ES formats.
Read more >
module not found: error: can't resolve 'fs' angular - You.com
The error is because of angular-cli does not support modules in node like "fs" and "path". (Issue). Add the following to the root...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found