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

When serving my app with the packed library used, I get this warning: enter image description here . Furthermore, when serving the app, I get this errormessage: enter image description here enter image description here

core_1 is imported alongside other modules in the top: import core_1, { Component, Inject, Injectable, InjectionToken, NgModule } from '@angular/core';

UPDATE!! The configuration is as follows: 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
  }
}
Estus Flask
  • 206,104
  • 70
  • 425
  • 565
kodeaben
  • 1,829
  • 3
  • 24
  • 33
  • Why is core_1 there? @angular/core isn't supposed to have default export. That's what the error on the first shot says. How does come that `core_1.Injectable` is used? The question lacks http://stackoverflow.com/help/mcve – Estus Flask Oct 20 '17 at 11:46
  • Hello @estus. Thanks for the comment. I was myself unsure if core_1 should be imported. For some reason ng-packagr packs it like this. I will update my question with the configurations. – kodeaben Oct 20 '17 at 12:21
  • If the question is specific to ng-packagr, I guess it can be solved more efficiently in repo issues, because the tool doesn't get much attention. But I've created ng-packagr tag. – Estus Flask Oct 20 '17 at 13:04
  • Thank you for your help @estus, it's much appreciated! – kodeaben Oct 20 '17 at 16:01
  • I have createed an issue on the ng-packagr repo : https://github.com/dherges/ng-packagr/issues/210 – kodeaben Oct 24 '17 at 06:18

1 Answers1

0

EUREKA

Fixed by playing with the tsconfig in both the library, and the angular project :

  • 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"
  ]
}

and in the target project :

  • tsconfig.json
{
   "compilerOptions": {
       "module": "esnext"
    }
}
  • tsconfig.app.json
{
   "compilerOptions": {
       "module": "esnext"
    }
}
Yacine MEDDAH
  • 1,211
  • 13
  • 17