Angular library `outside of the configured 'rootDir'` error when sharing dependencies

Viewed 108

I keep reading that you can use modules, components and interfaces within an Angular library. But I'm consistently getting an outside of the configured 'rootDir' error.

projects
  - app
  - lib
    - common-entry-pt
      - src
        - dumb.component-one.ts
        - dumb.component-two.ts
        - dumb.module.ts
        - ng-package.json
        - public-api.ts
    - entry-pt-one
      - src
        - entry-pt-one.component.ts 
        - entry-pt-one.module.ts <— importing dumb.module.ts gives “file outside of the configured ‘rootDir'"
        - entry-pt-one.service.ts
        - ng-package.json
        - public-api.ts

The code differs depending on import path or attempt.

error NG3004: Unable to import class ToolsModule.
dumb.module.ts is outside of the configured 'rootDir'.

Does anyone have an example of sharing deps within the library?

1 Answers

You can add the path alias to the tsconfig.json of the entry-pt-one library.

"paths": {
  "dumb-components-library": ["lib/src/common-entry-pt/public-api.ts"],
}

then in the modules of entry-pt-one you can do import using the alias:

import { Component } from 'dumb-components-library';

I think with that approach Angular should not complain about files out of the root dir.

Related