如果项目中存在动态链接的目录,则ng构建失败

时间:2018-10-20 17:51:13

标签: angular angular-cli

通常,我有几个项目要与他们共享组件。 我确实需要加快开发速度,并且如果我创建一个库项目,那么每当库发生更改时,我都需要构建和部署每个库。因此,我决定只创建一个包含共享组件的目录,并将这些组件动态链接到该项目。

我在MacOS Mojave 10.14上 使用NodeJS v10.12.0和angular cli v7.0.2

我的src/app文件夹具有以下内容:

16 -rw-r--r--   1 zoharzz  staff   792 Oct 20 19:21 app-routing.module.ts
16 -rw-r--r--   1 zoharzz  staff  1173 Oct 20 19:02 app.component.html
 0 -rw-r--r--   1 zoharzz  staff     0 Oct 20 19:02 app.component.scss
16 -rw-r--r--   1 zoharzz  staff  1113 Oct 20 19:02 app.component.spec.ts
16 -rw-r--r--   1 zoharzz  staff   222 Oct 20 19:02 app.component.ts
16 -rw-r--r--   1 zoharzz  staff  1508 Oct 20 20:19 app.module.ts
 0 drwxr-xr-x   6 zoharzz  staff   204 Oct 20 19:34 car-n-details-dialog
 0 drwxr-xr-x   6 zoharzz  staff   204 Oct 20 19:34 footer-toolbar
16 -rw-r--r--   1 zoharzz  staff   647 Oct 20 19:58 graphql.module.ts
 0 drwxr-xr-x   6 zoharzz  staff   204 Oct 20 19:34 home
 0 drwxr-xr-x   6 zoharzz  staff   204 Oct 20 19:34 products
 0 drwxr-xr-x   6 zoharzz  staff   204 Oct 15 16:14 terms-page
 0 drwxr-xr-x   6 zoharzz  staff   204 Oct 20 19:39 toolbar
16 lrwxr-xr-x   1 zoharzz  staff    45 Oct 20 20:22 tuxin-ec-accessibility -> ../../../tuxin-ec-libs/tuxin-ec-accessibility
16 lrwxr-xr-x   1 zoharzz  staff    43 Oct 20 19:13 tuxin-ec-breadcrumbs -> ../../../tuxin-ec-libs/tuxin-ec-breadcrumbs
16 lrwxr-xr-x   1 zoharzz  staff    36 Oct 20 19:13 tuxin-ec-cars -> ../../../tuxin-ec-libs/tuxin-ec-cars
16 lrwxr-xr-x   1 zoharzz  staff    36 Oct 20 19:13 tuxin-ec-cart -> ../../../tuxin-ec-libs/tuxin-ec-cart
16 lrwxr-xr-x   1 zoharzz  staff    42 Oct 20 19:13 tuxin-ec-contact-us -> ../../../tuxin-ec-libs/tuxin-ec-contact-us
 0 drwxr-xr-x   3 zoharzz  staff   102 Oct 20 20:18 tuxin-ec-libs
16 lrwxr-xr-x   1 zoharzz  staff    48 Oct 20 19:35 tuxin-ec-login-management -> ../../../tuxin-ec-libs/tuxin-ec-login-management
16 lrwxr-xr-x   1 zoharzz  staff    39 Oct 20 19:13 tuxin-ec-payment -> ../../../tuxin-ec-libs/tuxin-ec-payment
16 lrwxr-xr-x   1 zoharzz  staff    39 Oct 20 19:13 tuxin-ec-product -> ../../../tuxin-ec-libs/tuxin-ec-product
16 lrwxr-xr-x   1 zoharzz  staff    42 Oct 20 19:13 tuxin-ec-validators -> ../../../tuxin-ec-libs/tuxin-ec-validators

因此,当我尝试使用ng build -c development进行编译时,我得到:

ERROR in ../tuxin-ec-libs/tuxin-ec-accessibility/tuxin-ec-accessibility.component.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-accessibility/tuxin-ec-accessibility.component.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ../tuxin-ec-libs/tuxin-ec-breadcrumbs/tuxin-ec-breadcrumbs.component.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-breadcrumbs/tuxin-ec-breadcrumbs.component.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ../tuxin-ec-libs/tuxin-ec-cars/car-type/tuxin-ec-car-type.component.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-cars/car-type/tuxin-ec-car-type.component.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ../tuxin-ec-libs/tuxin-ec-cart/cart-page/tuxin-ec-cart-page.component.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-cart/cart-page/tuxin-ec-cart-page.component.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ../tuxin-ec-libs/tuxin-ec-cart/delivery-options/tuxin-ec-delivery-options.component.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-cart/delivery-options/tuxin-ec-delivery-options.component.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ../tuxin-ec-libs/tuxin-ec-cart/invoice/tuxin-ec-invoice.component.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-cart/invoice/tuxin-ec-invoice.component.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ../tuxin-ec-libs/tuxin-ec-cart/side-cart/tuxin-ec-side-cart.component.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-cart/side-cart/tuxin-ec-side-cart.component.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ../tuxin-ec-libs/tuxin-ec-cart/tuxin-ec-cart.service.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-cart/tuxin-ec-cart.service.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ../tuxin-ec-libs/tuxin-ec-contact-us/tuxin-ec-contact-us-graphql.service.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-contact-us/tuxin-ec-contact-us-graphql.service.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ../tuxin-ec-libs/tuxin-ec-contact-us/tuxin-ec-contact-us.component.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-contact-us/tuxin-ec-contact-us.component.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ../tuxin-ec-libs/tuxin-ec-login-management/login/tuxin-ec-login.component.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-login-management/login/tuxin-ec-login.component.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ../tuxin-ec-libs/tuxin-ec-login-management/tuxin-ec-user.service.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-login-management/tuxin-ec-user.service.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ../tuxin-ec-libs/tuxin-ec-payment/credit-card/tuxin-ec-credit-card.component.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-payment/credit-card/tuxin-ec-credit-card.component.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ../tuxin-ec-libs/tuxin-ec-payment/tuxin-ec-payment.component.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-payment/tuxin-ec-payment.component.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ../tuxin-ec-libs/tuxin-ec-product/hot-products/tuxin-ec-hot-products.component.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-product/hot-products/tuxin-ec-hot-products.component.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ../tuxin-ec-libs/tuxin-ec-product/product-card/tuxin-ec-product-card.component.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-product/product-card/tuxin-ec-product-card.component.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ../tuxin-ec-libs/tuxin-ec-product/tuxin-ec-category.service.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-product/tuxin-ec-category.service.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ERROR in ../tuxin-ec-libs/tuxin-ec-product/tuxin-ec-product.service.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /Volumes/osx-storage/projects/wd/tuxin-ec-libs/tuxin-ec-product/tuxin-ec-product.service.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:762:23)
    at plugin.done.then (/Volumes/osx-storage/projects/wd/windy-client/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)

将目录复制到项目中而不是动态链接它们时,我没有得到这些错误。

所以...有没有办法修改angular.json,以便它支持使用动态链接的目录?

这是我的angular.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "windy-client": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "tuxin-ec",
      "schematics": {
        "@schematics/angular:component": {
          "styleext": "scss"
        }
      },
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/windy-client",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
              "src/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                }
              ]
            },
            "development": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.dev.ts"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "windy-client:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "windy-client:build:production"
            },
            "development": {
              "browserTarget": "windy-client:build:development"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "windy-client:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
              "src/styles.scss"
            ],
            "scripts": [],
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "windy-client-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "prefix": "",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "windy-client:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "windy-client:serve:production"
            },
            "development": {
              "devServerTarget": "windy-client:serve:development"
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "windy-client"
}

1 个答案:

答案 0 :(得分:1)

在github上打开了一个问题,看来我缺少一个小的配置属性。

这是他们的答案:

You should be able to do so using preserveSymlinks either via the command line or via the options inside the angular.json under architect/build/options

Ex:

"architect": {
  "build": {
    "builder": "@angular-devkit/build-angular:browser",
    "options": {
      "preserveSymlinks": true,
      "index": "src/index.html",
      "main": "src/main.ts",
      ...
    }
  }
}
Check here: https://angular.io/cli/build