角度启用常春藤导致问题建立库

时间:2019-10-14 05:12:27

标签: angular angular-cli angular-ivy

问题

我创建了一个有角度的工作场所,其中包含一个应用程序和一个库。启用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构建cxi库 收到如下错误:

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

建筑入口点“ cxi-library”


通过ngc编译TypeScript源代码 错误:否:没有这样的文件或目录,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”。

1 个答案:

答案 0 :(得分:1)

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

ng build my-lib --prod

也许这会帮助某人...

编辑

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

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

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