1

问题

我创建了一个有角度的工作场所,其中包含一个应用程序和一个库。启用 IVY 后,在构建库时出现错误。但如果我将 enableIvy 设置为 false,它运行良好。

代码

tsconfig.json

 {
 "compileOnSave": false,
 "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": ["node_modules/@types"],
    "lib": ["es2018", "dom"],
    "paths": {
      "cxi-library": ["dist/cxi-library"],
      "cxi-library/*": ["dist/cxi-library/*"]
  }
},
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true,
    "enableIvy": true
  }
}

angular.json 的一部分

  "cxi-library": {
        "projectType": "library",
        "root": "projects/cxi-library",
        "sourceRoot": "projects/cxi-library/src",
        "prefix": "lib",
        "architect": {
          "build": {
            "builder": "@angular-devkit/build-ng-packagr:build",
            "options": {
              "tsConfig": "projects/cxi-library/tsconfig.lib.json",
              "project": "projects/cxi-library/ng-package.json"
            }
          },
          "test": {
            "builder": "@angular-devkit/build-angular:karma",
            "options": {
              "main": "projects/cxi-library/src/test.ts",
              "tsConfig": "projects/cxi-library/tsconfig.spec.json",
              "karmaConfig": "projects/cxi-library/karma.conf.js"
            }
          },
          "lint": {
            "builder": "@angular-devkit/build-angular:tslint",
            "options": {
              "tsConfig": [
               "projects/cxi-library/tsconfig.lib.json",
                "projects/cxi-library/tsconfig.spec.json"
              ],
              "exclude": ["**/node_modules/**"]
            }
          }
        }
      }

尝试运行 ng build cxi-library 收到如下错误:

** 不建议将 Ivy 库发布到 NPM 存储库 **

构建入口点'cxi-library'


通过 ngc 编译 TypeScript 源 ERROR: ENOENT: no such file or directory, scandir 'C:/cxi.registry.ui/cxi.registry.ui/C:/cxi.registry.ui/cxi.registry.ui/dist/cxi -library/cxi-library.d.ts' 发生未处理的异常:ENOENT: 没有这样的文件或目录,scandir 'C:/cxi.registry.ui/cxi.registry.ui/C:/cxi.registry.ui/ cxi.registry.ui/dist/cxi-library/cxi-library.d.ts' 参见“C:\Users\JUNXIL~1.FOX\AppData\Local\Temp\ng-tIrBUR\angular-errors.log”更多详细信息。

4

1 回答 1

1

我有一个类似的问题。这是因为我没有使用“--prod”选项构建我的库。

ng build my-lib --prod

也许这会帮助某人......

编辑

请注意,“--prod”标志将编译器选项“enableIvy”设置为 false。所以如果你安装了依赖,你可能需要调用 Angular 兼容性编译器。您可能需要为此使用安装后脚本:

"scripts": {
   "postinstall": "ngcc"
}

来源:https ://angular.io/guide/ivy#maintaining-library-compatibility

于 2020-04-20T12:26:28.113 回答