Angular-自定义库无法读取未定义的属性“指令”

时间:2018-11-20 15:17:08

标签: angular angular-cli rollupjs angular-module angular-library

我正在创建一个自定义Angular 7库,其中包含公司所有项目中常见的一些指令,管道和提供程序;但是,在另一个项目中使用我创建的模块时,我面临着这个奇怪的问题:

h2r-shared-base.js?9483:1023 Uncaught TypeError: Cannot read property 'Directive' of undefined
    at eval (h2r-shared-base.js?9483:1023)
    at eval (h2r-shared-base.js?9483:1047)
    at createCommonjsModule (h2r-shared-base.js?9483:18)
    at eval (h2r-shared-base.js?9483:724)
    at Object../node_modules/@h2r/shared-base/fesm5/h2r-shared-base.js (main.bundle.js:955)
    at __webpack_require__ (main.bundle.js:712)
    at fn (main.bundle.js:95)
    at eval (user.service.ts?cada:7)
    at Object../src/main/webapp/app/shared/user/user.service.ts (main.bundle.js:11328)
    at __webpack_require__ (main.bundle.js:712)
(anonymous) @ h2r-shared-base.js?9483:1023
(anonymous) @ h2r-shared-base.js?9483:1047
createCommonjsModule @ h2r-shared-base.js?9483:18
(anonymous) @ h2r-shared-base.js?9483:724
./node_modules/@h2r/shared-base/fesm5/h2r-shared-base.js @ main.bundle.js:955
__webpack_require__ @ main.bundle.js:712
fn @ main.bundle.js:95
(anonymous) @ user.service.ts?cada:7
./src/main/webapp/app/shared/user/user.service.ts @ main.bundle.js:11328
__webpack_require__ @ main.bundle.js:712
fn @ main.bundle.js:95
(anonymous) @ index.ts?0ab5:7
./src/main/webapp/app/shared/index.ts @ main.bundle.js:11184
__webpack_require__ @ main.bundle.js:712
fn @ main.bundle.js:95
(anonymous) @ app.module.ts?c5f8:6
./src/main/webapp/app/app.module.ts @ main.bundle.js:9102
__webpack_require__ @ main.bundle.js:712
fn @ main.bundle.js:95
(anonymous) @ app.main.ts?38fd:3
./src/main/webapp/app/app.main.ts @ main.bundle.js:9090
__webpack_require__ @ main.bundle.js:712
fn @ main.bundle.js:95
2 @ main.bundle.js:11398
__webpack_require__ @ main.bundle.js:712
(anonymous) @ main.bundle.js:764
(anonymous) @ main.bundle.js:767

./node_modules/@h2r/shared-base/fesm5/h2r-shared-base.js
1023:16-20 "export 'default' (imported as 'core') was not found in '@angular/core'

这是lib项目的angular.json:

{
 "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
 "version": 1,
 "newProjectRoot": "projects",
 "projects": {
   "shared-base": {
     "root": "projects/shared-base",
     "sourceRoot": "projects/shared-base/src",
     "projectType": "library",
     "prefix": "h2r",
     "architect": {
       "build": {
         "builder": "@angular-devkit/build-ng-packagr:build",
         "options": {
           "tsConfig": "projects/shared-base/tsconfig.lib.json",
           "project": "projects/shared-base/ng-package.json"
         }
       },
       "test": {
         "builder": "@angular-devkit/build-angular:karma",
         "options": {
           "main": "projects/shared-base/test/test.ts",
           "tsConfig": "projects/shared-base/test/tsconfig.spec.json",
           "karmaConfig": "projects/shared-base/test/karma.conf.js"
         }
       },
       "lint": {
         "builder": "@angular-devkit/build-angular:tslint",
         "options": {
           "tsConfig": [
             "projects/shared-base/tsconfig.lib.json",
             "projects/shared-base/test/tsconfig.spec.json"
           ],
           "exclude": [
             "**/node_modules/**"
           ]
         }
       }
     }
   }
 },
 "defaultProject": "shared-modules"
}

我不知道为什么,看来它找不到@ angular / core。有人可以解释一下是什么原因引起的吗?

0 个答案:

没有答案