角度库问题,同时包含在另一个单独的项目中

时间:2019-08-13 07:10:58

标签: angular angular-library

我正在尝试创建一个angular-library并将其导出为@nivite/nlib。库本身有一个test project,它可以用ng build --prod

构建

但是当我创建单独的app并尝试执行ng build --prod时,请使用以下命令 kaboom

// error
ERROR in ./node_modules/@nivite/nlib/nlib.ngfactory.js
Module not found: Error: Can't resolve 'nlib' in '/home/chakru/aws/n00001/node_modules/@nivite/nlib'
resolve 'nlib' in '/home/chakru/aws/n00001/node_modules/@nivite/nlib'
  Parsed request is a module
  using description file: /home/chakru/aws/n00001/node_modules/@nivite/nlib/package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in /home/chakru/aws/n00001/
        using description file: /home/chakru/aws/n00001/package.json (relative path: .)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /home/chakru/aws/n00001/package.json (relative path: ./nlib)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/nlib doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/nlib.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/nlib.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/nlib.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/nlib.js doesn't exist
            as directory
              /home/chakru/aws/n00001/nlib doesn't exist
      /home/chakru/aws/n00001/node_modules/@nivite/nlib/node_modules doesn't exist or is not a directory
      /home/chakru/aws/n00001/node_modules/@nivite/node_modules doesn't exist or is not a directory
      /home/chakru/aws/n00001/node_modules/node_modules doesn't exist or is not a directory
      /home/chakru/aws/node_modules doesn't exist or is not a directory
      /home/chakru/node_modules doesn't exist or is not a directory
      /home/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /home/chakru/aws/n00001/node_modules
        using description file: /home/chakru/aws/n00001/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /home/chakru/aws/n00001/package.json (relative path: ./node_modules/nlib)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/node_modules/nlib doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/node_modules/nlib.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/node_modules/nlib.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/node_modules/nlib.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/node_modules/nlib.js doesn't exist
            as directory
              /home/chakru/aws/n00001/node_modules/nlib doesn't exist
[/home/chakru/aws/n00001/nlib]
[/home/chakru/aws/n00001/nlib.ts]
[/home/chakru/aws/n00001/nlib.tsx]
[/home/chakru/aws/n00001/nlib.mjs]
[/home/chakru/aws/n00001/nlib.js]
[/home/chakru/aws/n00001/node_modules/@nivite/nlib/node_modules]
[/home/chakru/aws/n00001/node_modules/@nivite/node_modules]
[/home/chakru/aws/n00001/node_modules/node_modules]
[/home/chakru/aws/node_modules]
[/home/chakru/node_modules]
[/home/node_modules]
[/node_modules]
[/home/chakru/aws/n00001/node_modules/nlib]
[/home/chakru/aws/n00001/node_modules/nlib.ts]
[/home/chakru/aws/n00001/node_modules/nlib.tsx]
[/home/chakru/aws/n00001/node_modules/nlib.mjs]
[/home/chakru/aws/n00001/node_modules/nlib.js]
 @ ./node_modules/@nivite/nlib/nlib.ngfactory.js 8:0-27 16:62-75 16:4568-4581 16:4583-4596 394:89-105 394:108-113 394:131-136 394:148-162 396:80-96
 @ ./src/app/app.component.ngfactory.js
 @ ./src/app/app.module.ngfactory.js
 @ ./src/main.ts
 @ multi ./src/main.ts
ERROR in ./src/app/app.module.ngfactory.js
Module not found: Error: Can't resolve 'nlib' in '/home/chakru/aws/n00001/src/app'
resolve 'nlib' in '/home/chakru/aws/n00001/src/app'
  Parsed request is a module
  using description file: /home/chakru/aws/n00001/package.json (relative path: ./src/app)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in /home/chakru/aws/n00001/
        using description file: /home/chakru/aws/n00001/package.json (relative path: .)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /home/chakru/aws/n00001/package.json (relative path: ./nlib)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/nlib doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/nlib.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/nlib.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/nlib.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/nlib.js doesn't exist
            as directory
              /home/chakru/aws/n00001/nlib doesn't exist
      /home/chakru/aws/n00001/src/app/node_modules doesn't exist or is not a directory
      /home/chakru/aws/n00001/src/node_modules doesn't exist or is not a directory
      /home/chakru/aws/node_modules doesn't exist or is not a directory
      /home/chakru/node_modules doesn't exist or is not a directory
      /home/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /home/chakru/aws/n00001/node_modules
        using description file: /home/chakru/aws/n00001/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /home/chakru/aws/n00001/package.json (relative path: ./node_modules/nlib)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/node_modules/nlib doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/node_modules/nlib.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/node_modules/nlib.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/node_modules/nlib.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/node_modules/nlib.js doesn't exist
            as directory
              /home/chakru/aws/n00001/node_modules/nlib doesn't exist
[/home/chakru/aws/n00001/nlib]
[/home/chakru/aws/n00001/nlib.ts]
[/home/chakru/aws/n00001/nlib.tsx]
[/home/chakru/aws/n00001/nlib.mjs]
[/home/chakru/aws/n00001/nlib.js]
[/home/chakru/aws/n00001/src/app/node_modules]
[/home/chakru/aws/n00001/src/node_modules]
[/home/chakru/aws/node_modules]
[/home/chakru/node_modules]
[/home/node_modules]
[/node_modules]
[/home/chakru/aws/n00001/node_modules/nlib]
[/home/chakru/aws/n00001/node_modules/nlib.ts]
[/home/chakru/aws/n00001/node_modules/nlib.tsx]
[/home/chakru/aws/n00001/node_modules/nlib.mjs]
[/home/chakru/aws/n00001/node_modules/nlib.js]
 @ ./src/app/app.module.ngfactory.js 18:0-28 19:4609-4623 19:4625-4639
 @ ./src/main.ts
 @ multi ./src/main.ts
ERROR in ./src/app/app.component.ngfactory.js
Module not found: Error: Can't resolve 'nlib' in '/home/chakru/aws/n00001/src/app'
resolve 'nlib' in '/home/chakru/aws/n00001/src/app'
  Parsed request is a module
  using description file: /home/chakru/aws/n00001/package.json (relative path: ./src/app)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in /home/chakru/aws/n00001/
        using description file: /home/chakru/aws/n00001/package.json (relative path: .)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /home/chakru/aws/n00001/package.json (relative path: ./nlib)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/nlib doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/nlib.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/nlib.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/nlib.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/nlib.js doesn't exist
            as directory
              /home/chakru/aws/n00001/nlib doesn't exist
      /home/chakru/aws/n00001/src/app/node_modules doesn't exist or is not a directory
      /home/chakru/aws/n00001/src/node_modules doesn't exist or is not a directory
      /home/chakru/aws/node_modules doesn't exist or is not a directory
      /home/chakru/node_modules doesn't exist or is not a directory
      /home/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /home/chakru/aws/n00001/node_modules
        using description file: /home/chakru/aws/n00001/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /home/chakru/aws/n00001/package.json (relative path: ./node_modules/nlib)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/node_modules/nlib doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/node_modules/nlib.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/node_modules/nlib.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/node_modules/nlib.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /home/chakru/aws/n00001/node_modules/nlib.js doesn't exist
            as directory
              /home/chakru/aws/n00001/node_modules/nlib doesn't exist
[/home/chakru/aws/n00001/nlib]
[/home/chakru/aws/n00001/nlib.ts]
[/home/chakru/aws/n00001/nlib.tsx]
[/home/chakru/aws/n00001/nlib.mjs]
[/home/chakru/aws/n00001/nlib.js]
[/home/chakru/aws/n00001/src/app/node_modules]
[/home/chakru/aws/n00001/src/node_modules]
[/home/chakru/aws/node_modules]
[/home/chakru/node_modules]
[/home/node_modules]
[/node_modules]
[/home/chakru/aws/n00001/node_modules/nlib]
[/home/chakru/aws/n00001/node_modules/nlib.ts]
[/home/chakru/aws/n00001/node_modules/nlib.tsx]
[/home/chakru/aws/n00001/node_modules/nlib.mjs]
[/home/chakru/aws/n00001/node_modules/nlib.js]
 @ ./src/app/app.component.ngfactory.js 11:0-27 41:95-111 41:114-119 41:137-142 41:154-168 43:234-248
 @ ./src/app/app.module.ngfactory.js
 @ ./src/main.ts
 @ multi ./src/main.ts

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { NlibModule } from '@nivite/nlib';
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NlibModule    // ------> the issue is here! <------
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

package.json

{
  "name": "n00001",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "deploy": "ng deploy --base-href=/n00001/"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.2.0",
    "@angular/common": "~8.2.0",
    "@angular/compiler": "~8.2.0",
    "@angular/core": "~8.2.0",
    "@angular/fire": "^5.2.1",
    "@angular/forms": "~8.2.0",
    "@angular/platform-browser": "~8.2.0",
    "@angular/platform-browser-dynamic": "~8.2.0",
    "@angular/router": "~8.2.0",
    "@nivite/nlib": "^1.0.9",
    "angular-cli-ghpages": "^0.6.0-rc.2",
    "bootstrap": "^4.3.1",
    "file-saver": "^2.0.2",
    "firebase": "^6.3.5",
    "moment": "^2.24.0",
    "moment-timezone": "^0.5.26",
    "ngx-markdown": "^8.1.0",
    "rxjs": "~6.4.0",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.803.0-next.1",
    "@angular/cli": "~8.3.0-next.1",
    "@angular/compiler-cli": "~8.2.0",
    "@angular/language-service": "~8.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.0.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
  }
}

任何线索,任何人?

1 个答案:

答案 0 :(得分:0)

通过将name fixed中的nlib值从@nivite/nlib更改为./projects/nlib/package.json来解决。

PS:错误消息不是很明智,必须bruteforce进行修复!