angular-quickstart-lib icon indicating copy to clipboard operation
angular-quickstart-lib copied to clipboard

Problems with ngc builds of external dependency

Open lvanderbijl opened this issue 7 years ago • 3 comments

Hi,

I'm using applicationinsights as a dependency for an angular library I'm creating.

I'm using applicationinsights 1.0.4 and the typings v1.0.4.

I'm using applicationinsights in a service like this (typescript file): import { AppInsights } from 'applicationinsights-js';

However when the compiler converts it to an es2015 module, the import becomes: import { AppInsights } from 'applicationinsights-js/index'; (note the extra: /index at the end)

which is obviously wrong and breaks. Any ideas why this is occuring? I feel like it's something to do with the way the @types works but can't work out why.

Here's a sample of the tsconfig I'm using (tsconfig.es5.json)

{
  "extends": "./tsconfig.lib.json",
  "compilerOptions": {
    "target": "es5",
    "outDir": "../../out-tsc/lib-es5/",
    "baseUrl": "",
    "typeRoots": [

      "../../node_modules/@types/"
    ],
    "types": ["applicationinsights-js"]
  },
  "files": [
    "./index.ts",
    "./typings.d.ts"
  ],
  "angularCompilerOptions": {
    "annotateForClosureCompiler": true,
    "strictMetadataEmit": true,
    "skipTemplateCodegen": true,
    "flatModuleOutFile": "logging-ng.js",
    "flatModuleId": "logging-ng",
    "genDir": "../../out-tsc/lib-gen-dir/"
  }
}

Note that I added types and typeroots but it doesn't seem to make any difference.

Thanks for your time Leander

lvanderbijl avatar Jul 06 '17 09:07 lvanderbijl

this seems to be the same as #50

Bengreen avatar Aug 02 '17 15:08 Bengreen

I had similar problem with importing uirouter/angular-hybrid. Try adding paths object to rollupBaseConfig object in build.js file located in root of library, i.e.

const rollupBaseConfig = {
   moduleName: camelCase(libName),
   sourceMap: true,
   globals: {
     '@angular/core': 'ng.core'
   },
   external: [
     '@angular/core'
   ],
   paths: {
     'applicationinsights-js/index': 'applicationinsights-js'
   },
   plugins: [
     sourcemaps()
   ]
 };

adamlubek avatar Aug 02 '17 15:08 adamlubek

My similar problem in issue #50 was solved by adding paths: { 'xxx/index': 'xxx' } in rollup config. Thank you @adamlubek for this.

kmolerov avatar Aug 04 '17 08:08 kmolerov