共享依赖项时,Angular 库“位于配置的‘rootDir’之外”错误

Ben*_*cot 6 shared-libraries angular

我一直读到您可以在 Angular 库中使用模块、组件和接口。但我一直收到outside of the configured 'rootDir'错误。

\n
projects\n  - app\n  - lib\n    - common-entry-pt\n      - src\n        - dumb.component-one.ts\n        - dumb.component-two.ts\n        - dumb.module.ts\n        - ng-package.json\n        - public-api.ts\n    - entry-pt-one\n      - src\n        - entry-pt-one.component.ts \n        - entry-pt-one.module.ts <\xe2\x80\x94 importing dumb.module.ts gives \xe2\x80\x9cfile outside of the configured \xe2\x80\x98rootDir'"\n        - entry-pt-one.service.ts\n        - ng-package.json\n        - public-api.ts\n
Run Code Online (Sandbox Code Playgroud)\n

该代码根据导入路径或尝试的不同而有所不同。

\n
error NG3004: Unable to import class ToolsModule.\ndumb.module.ts is outside of the configured 'rootDir'.\n
Run Code Online (Sandbox Code Playgroud)\n

有人有在图书馆内共享部门的例子吗?

\n

更新:\n我从头开始并严格使用 cli 来重新创建每个文件/文件夹。没有什么不同,而且有效。

\n

Tel*_*bov 0

您可以将路径别名添加到tsconfig.json库的路径别名中entry-pt-one

"paths": {
  "dumb-components-library": ["lib/src/common-entry-pt/public-api.ts"],
}
Run Code Online (Sandbox Code Playgroud)

然后在模块中entry-pt-one您可以使用别名进行导入:

import { Component } from 'dumb-components-library';
Run Code Online (Sandbox Code Playgroud)

我认为通过这种方法,Angular 不应该抱怨根目录之外的文件。

  • 这正是导致“超出配置的‘rootDir’’错误的原因。 (3认同)