'@ angular / core'中未找到“export'default'(导入为'core_1')

时间:2017-10-20 10:35:10

标签: javascript angular webpack ng-packagr

I'm building an Angular library with ng-packagr. 

使用打包的库提供我的应用程序时,我收到此警告: enter image description here 。此外,在为应用程序提供服务时,我收到此错误消息: enter image description here enter image description here

core_1与顶部的其他模块一起导入: import core_1, { Component, Inject, Injectable, InjectionToken, NgModule } from '@angular/core';

UPDATE !! 配置如下: NG-的package.json

{
  "$schema": "./node_modules/ng-packagr/ng-package.schema.json",
  "src": "lib",
  "dest": "dist/auth",
  "workingDirectory": ".ng_build",
  "lib": {
    "entryFile": "public_api.ts",
    "externals": {
      "oidc-client": "./node_modules/oidc-client/dist/oidc-client.min.js",
      "rxjs/add/operator/let": "Rx.Observable.prototype"
    }
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "lib": [
      "es6",
      "dom"
    ],
    "moduleResolution": "node",
    "declaration": true,
    "experimentalDecorators": true,
    "baseUrl": ".",
    "stripInternal": true,
    "outDir": "./dist",
    "sourceMap": true,
    "inlineSources": true,
    "skipLibCheck": true
  },
  "exclude": [
    "node_modules",
    "dist",
    "demo",
    "config",
    "coverage",
    "src/**/*.spec.ts"
  ],
  "angularCompilerOptions": {
    "strictMetadataEmit": true,
    "skipTemplateCodegen": true,
    "trace": true
  }
}

1 个答案:

答案 0 :(得分:0)

EUREKA

通过在库和Angular项目中同时使用tsconfig进行修复:

  • tsconfig.lib.json
{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    // ? these two lines
    "target": "es2015",
    "module": "esnext",
  },
  "angularCompilerOptions": {
    "annotateForClosureCompiler": true,
    "skipTemplateCodegen": true,
    "strictMetadataEmit": true,
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true,
    "enableResourceInlining": true
  },
  "exclude": [
    "src/test.ts",
    "**/*.spec.ts"
  ]
}

并在目标项目中:

  • tsconfig.json
{
   "compilerOptions": {
       "module": "esnext"
    }
}
  • tsconfig.app.json
{
   "compilerOptions": {
       "module": "esnext"
    }
}