angular-quickstart-lib
angular-quickstart-lib copied to clipboard
Problems with ngc builds of external dependency
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
this seems to be the same as #50
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()
]
};
My similar problem in issue #50 was solved by adding paths: { 'xxx/index': 'xxx' } in rollup config. Thank you @adamlubek for this.