标签: ng-packagr

'rootDir'应包含所有源文件

我有一个Angular CLI工作区,包含两个库项目,foobar.当我构建两个库中的第二个时foo,构建失败并出现以下错误:

错误TS6059:文件'/code/projects/bar/src/lib/types.ts'不在'rootDir''/ code/projects/foo/src'下.'rootDir'预计会包含所有源文件.

Error: error TS6059: File '/code/projects/bar/src/lib/types.ts' is not under 'rootDir' '/code/projects/foo/src'. 'rootDir' is expected to contain all source files.

    at Object.<anonymous> (/code/node_modules/ng-packagr/lib/ngc/compile-source-files.js:53:68)
    at Generator.next (<anonymous>)
    at /code/node_modules/ng-packagr/lib/ngc/compile-source-files.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/code/node_modules/ng-packagr/lib/ngc/compile-source-files.js:3:12)
    at Object.compileSourceFiles (/code/node_modules/ng-packagr/lib/ngc/compile-source-files.js:19:12)
    at Object.<anonymous> (/code/node_modules/ng-packagr/lib/ng-v5/entry-point/ts/compile-ngc.transform.js:26:32)
    at Generator.next (<anonymous>)
    at /code/node_modules/ng-packagr/lib/ng-v5/entry-point/ts/compile-ngc.transform.js:7:71
    at new Promise (<anonymous>)
Run Code Online (Sandbox Code Playgroud)

我已复制了错误的沙箱回购GitHub上这里.我仍然遇到错误,尽可能地简化了代码.您可以通过npm run buildrootDir-expect-all-source-files-error分支上执行来重现错误.错误的原因是什么?可能这是一个或与ng-packagr或的错误?或者只是一个配置问题?ngctsc

意见

下面是我可以进行构建传递的代码更改,但我想知道导致错误的原因是什么.

bar.component.ts

构建失败

export class BarComponent …
Run Code Online (Sandbox Code Playgroud)

typescript angular-cli angular angular-library ng-packagr

12
推荐指数
5
解决办法
1万
查看次数

Angular 9 ng build --prod 中的“超出了最大调用堆栈大小”

我有一个可以用 Angular 9 编译的库。但是如果我将标志更改为 --prod,这实际上使得"enableIvy": false我得到

[错误] RangeError:超出最大调用堆栈大小

在 Object.pathIsRelative (...\node_modules\typescript\lib\typescript.js:5778:34)

在 tryLoadModuleUsingPathsIfEligible (...\node_modules\typescript\lib\typescript.js:28346:37)

在 tryLoadModuleUsingOptionalResolutionSettings (...\node_modules\typescript\lib\typescript.js:28334:24)

在 tryResolve (...\node_modules\typescript\lib\typescript.js:28479:28)

在...\node_modules\typescript\lib\typescript.js:28471:69

在 Object.forEach (...\node_modules\typescript\lib\typescript.js:309:30)

在nodeModuleNameResolverWorker (...\node_modules\typescript\lib\typescript.js:28471:25)

在nodeModuleNameResolver (...\node_modules\typescript\lib\typescript.js:28464:16)

在 Object.resolveModuleName (...\node_modules\typescript\lib\typescript.js:28238:30)

在 CompilerHostAdapter.getMetadataFor (...\node_modules@angular\compiler-cli\src\metadata\bundler.js:567:37)

我在函数中引入了控制台调试消息function tryLoadModuleUsingPathsIfEligible(extensions, moduleName, loader, state),它似乎是一个大约 20moduleName秒的循环。我必须提到,如果我在没有标志的情况下编译,我不会有任何循环依赖警告--prod

更新:我修复了循环依赖关系,并且不再有任何警告。

typescript angular ng-packagr

12
推荐指数
2
解决办法
2万
查看次数

使用 NX 和 Angular 对可发布库进行对等依赖配置

我有一个使用 NX 和 Angular 的 monorepo,我正在向 NPM 发布一些库,我有以下场景

\n
apps\n   only_App\nlibs\n   lib_A // v1.0.0\n   lib_B // v1.0.0\n   lib_C // v1.0.0\n
Run Code Online (Sandbox Code Playgroud)\n

lib_A 依赖于 lib_B 和 lib_C。

\n

预构建的package.json中lib_A没有\xe2\x80\x99t 有任何peerDependency并且在我构建它之前发布它之后,自动添加对等依赖项,例如

\n
// BUILT lib_A/package.json\n\n{\n...,\n"peerDependencies":{\n   "@myScope/lib-b": "1.0.0", //specifically that version\n   "@myScope/lib-c": "1.0.0",\n}\n}\n
Run Code Online (Sandbox Code Playgroud)\n

问题是当我lib_A在另一个项目中发布并使用它时(在 NX 和此存储库之外)。它总是期望我使用lib_Bv1.0.0 lib_C \n如果我打补丁lib_B将其升级到v1.0.1,那么我也被迫重建lib_A更新peerDependency版本。也发布lib_A和升级lib_A版本。

\n

有没有办法可以配置它,以便在构建时lib_A将其添加^到我的库中?IE

\n
// BUILT lib_A/package.json\n\n{\n...,\n"peerDependencies":{\n   "@myScope/lib-b": "^1.0.0", //automatically …
Run Code Online (Sandbox Code Playgroud)

npm npm-publish angular ng-packagr nrwl

12
推荐指数
1
解决办法
4121
查看次数

不推荐在“package.json”中配置 ng-packagr

在构建带有子条目的 Angular 13 包时,我收到以下警告。

Building Angular Package
WARNING: Found configuration in ...<PATH_TO_PACKAGE>/package.json.
Configuring ng-packagr in "package.json" is deprecated. Use "ng-package.json" instead.
Run Code Online (Sandbox Code Playgroud)

所有相关信息均源自ng version

Angular CLI: 13.0.4
Node: 16.13.0
Package Manager: yarn 1.22.17
OS: linux x64

Angular: 13.0.3
... animations, cdk, common, compiler, compiler-cli, core
... elements, forms, language-service, material
... material-moment-adapter, platform-browser
... platform-browser-dynamic, router, service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1300.3
@angular-devkit/build-angular   13.0.4
@angular-devkit/core            13.0.3
@angular-devkit/schematics      13.0.3
@angular/cli                    13.0.4
@schematics/angular             13.0.4
ng-packagr                      13.0.8
rxjs                            7.4.0
typescript                      4.4.4
Run Code Online (Sandbox Code Playgroud)

不知道这是否是误报或如何解决它,因为官方 ng-packagr …

angular-cli ng-packagr

11
推荐指数
1
解决办法
7287
查看次数

警告:在 output.globals 中没有为外部模块“X”提供名称——猜测是“X”

WARNING: No name was provided for external module 'moment' in output.globals – guessing 'momentImported'
WARNING: No name was provided for external module 'odata-parser' in output.globals – guessing 'parser'
Run Code Online (Sandbox Code Playgroud)

当我尝试将我的库绑定到通用模块定义时收到此消息。警告可以通过在 ng-package.json 中添加 umdModuleIds 来修复。

文件为我们提供了以下解释:

在编写 UMD 包时,ng-packagr 尽最大努力为 UMD 模块标识符提供通用默认值。此外, rollup 将尽最大努力猜测外部依赖项的模块 ID。即使这样,您也应该确保外部依赖项的 UMD 模块标识符是正确的。如果 ng-packagr 不提供默认值并且 rollup 无法猜测正确的标识符,您应该通过在库的包文件部分中使用 umdModuleIds 来明确提供模块标识符,如下所示:...

umdModuleIds

外部依赖关系及其对应的 UMD 模块标识符的映射。Map 键是 TypeScript / EcmaScript 模块标识符。映射值是 UMD 模块 ID。此映射的目的是正确捆绑 UMD 模块文件(带有rollup)。默认情况下,支持rxjs,tslib@angular/*依赖项符号。

如何查找或检查必须添加到 umdModuleIds …

umd rollupjs angular ng-packagr

10
推荐指数
1
解决办法
7833
查看次数

具有子入口点循环依赖的 Angular 9 库

我有一个关于角度库辅助入口点设置的非常具体的问题。我真的不明白当它们相互依赖(包括主入口点)时,如何设置它才能使其工作。我已经阅读了 ng-packagr 的文档以及很多问题和堆栈问题,但没有找到真正好的答案。问题是,我想将我们庞大的内部库分解成更小的部分,以便对于不需要一切的应用程序来说,导入和依赖项变得更小。

所以这就是我想要达到的目标:

  • 主库@my/my-lib
  • 辅助路径@my/my-lib/functions
  • 辅助路径@my/my-lib/constants
  • 辅助路径@my/my-lib/lang
  • 辅助路径@my/my-lib/broker
  • 辅助路径@my/my-lib/signalr
  • 辅助路径@my/my-lib/sso
  • 辅助路径@my/my-lib/types

这就是文件夹结构:

projects\my-lib
-- constants\
---- ...
---- package.json
---- public_api.ts
-- functions\
---- ...
---- package.json
---- public_api.ts
-- lang
---- ...
---- package.json
---- public_api.ts
-- broker
---- ...
---- package.json
---- public_api.ts
-- signalr
---- ...
---- package.json
---- public_api.ts
-- sso
---- ...
---- package.json
---- public_api.ts
-- src <-- the main entry point, as setup from the ng g library
---- lib
------ modules …
Run Code Online (Sandbox Code Playgroud)

angular angular-library ng-packagr

9
推荐指数
1
解决办法
1万
查看次数

构建 Angular 库时“不受支持的私有类 xy”

我正在使用 Angular 开发一个 npm 包。在构建库时,我收到以下错误:

不受支持的私有类 MyLibComponent。此类通过 MyLibModule -> MyLibComponent 对使用者可见,但不会从顶级库入口点导出。

我发现了这个问题。这解释了我如何修复它,但不是为什么我需要将所有组件放入桶文件中,如NgModules 的Angular 文档所述:

导出的声明是模块的公共 API。

谁可以给我解释一下这个?

typescript angular ng-packagr

9
推荐指数
1
解决办法
3975
查看次数

当导入 Angular 13 项目时,Angular 13 包/库抛出错误“moment is not a function”

我正在升级私有角度库/包(my-lib),以便我可以迁移所有其他项目,但是当导入到项目中时,其中一项服务使用 moment 并抛出错误:“错误类型错误:moment 不是函数”

该库在开发模式下工作,构建和发布都正常,即使导入到项目中,所有组件和资源都加载良好并且没有显示错误,依赖项已下载,但似乎某些 3rd 方依赖项不被“我的”所知-lib”导入后。

即使在项目中,我也可以导入 moment 并使用它,但 node_modules 中的“my-lib”看不到该包。

“my-lib”中的一些文件

服务.ts

import * as moment_ from 'moment';

const moment = moment_;
...

moment(value).format('YYYY-MM-DD')  ----> line that throws the error
Run Code Online (Sandbox Code Playgroud)

已经尝试过

import moment from 'moment';
Run Code Online (Sandbox Code Playgroud)

以及 tsconfig 中的“allowSyntheticDefaultImports”标志

包.json

"dependencies": {
    ...
    "moment": "~2.29.1",
    ...
},
"devDependencies": {
    "@angular-builders/custom-webpack": "~13.0.0",
    "@angular-devkit/build-angular": "~13.1.1",
    "@angular-eslint/builder": "~13.0.1",
    "@angular-eslint/eslint-plugin": "~13.0.1",
    "@angular-eslint/eslint-plugin-template": "~13.0.1",
    "@angular-eslint/schematics": "~13.0.1",
    "@angular-eslint/template-parser": "~13.0.1",
    "@angular/animations": "~13.1.0",
    "@angular/cli": "~13.1.1",
    "@angular/common": "~13.1.0",
    "@angular/compiler": "~13.1.0",
    "@angular/compiler-cli": "~13.1.0",
    "@angular/core": "~13.1.0",
    "@angular/forms": "~13.1.0",
    "@angular/language-service": "~13.1.0", …
Run Code Online (Sandbox Code Playgroud)

momentjs typescript angular angular-library ng-packagr

9
推荐指数
1
解决办法
7112
查看次数

ng build --prod(AOT)时装饰器不支持函数调用

问题类型:错误/问题

描述

我正在使用ng-packagr lib将我的库编译为js.我编译了所有内容没有任何问题,但是当我想要使用ng build --prod(启用AOT)来使用我的库时,我收到错误:

ERROR in Error during template compile of 'AppModule' Function calls are not supported in decorators but 'BsDropdownModule' was called.

当我删除.forRoot方法时,我收到错误:

ERROR in : Unexpected value 'BsDropdownModule in /home/sf/Desktop/Developerka/kompilacja/final/sample-repo/node_modules/angular-library-name/free/dropdown/dropdown.module.d.ts' imported by the module 'AppModule in /home/sf/Desktop/Developerka/kompilacja/final/sample-repo/src/app/app.module.ts'. Please add a @NgModule annotation

请注意,这ng --prod --aot=false 不会产生任何错误.

如何重现:

下载repo:https://github.com/Bloodcast69/aot-error,输入 npm install ng build --prod.

预期的行为

想要使用AOT构建没有错误(我需要它与Angular Universal兼容)版本信息

ng-packagr: 2.4.1 @angular/*: 5.2.9 typescript: 2.5.3 rxjs: 5.5.6 node: 8.1.0 npm/yarn: npm: 5.6.0

文件:

app.module.ts: …

typescript angular-universal angular2-aot angular ng-packagr

8
推荐指数
1
解决办法
5171
查看次数

无法从节点模块使用 SASS mixin 构建 Angular 库

设置:带有库的 Angular 9 工作区、一个使用 CDK 的测试应用程序和故事书_overlay.scss.scss文件中包含@use.

.storybook/
node_modules/
projects/
- library/
  - src/
    - lib/
      - component/
        component.scss // `@use`s `_overlay.scss`
  ng-package.json
- test-app/
angular.json
Run Code Online (Sandbox Code Playgroud)

问题:@use "~@angular/cdk/overlay"在测试应用程序和故事书编译中使用覆盖 sass 混合但 ng-packagr 找不到_overlay.scss.

ERROR: Can't find stylesheet to import.
  ?
2 ? @use "~@angular/cdk/overlay";
  ? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ?
  projects\library\src\lib\component\component.scss 2:1  root stylesheet
An unhandled exception occurred: Can't find stylesheet to import.
Run Code Online (Sandbox Code Playgroud)

解决方法:

  • 可以添加node_modules/tong-package.json"styleIncludePaths": "["../../node_modules"]"数组并像这样导入覆盖混合,@use …

sass angular ng-packagr

8
推荐指数
0
解决办法
565
查看次数