ng-packagr: export 'default' (imported as 'core_1') was not found in '@angular/core'
Type of Issue
[x] Bug Report
[ ] Feature Request
Versions
ng-packagr: v1.5.0-rc.1
node: v6.11.0
@angular: v4.4.6
rxjs: 5.5.0
zone.js: 0.8.18
Description
When packaging my library i get the following warning:
'default' is not exported by 'node_modules\redux\es\index.js'
'default' is imported from external module 'rxjs/add/operator/let' but never used
'default' is imported from external module 'rxjs/add/operator/distinctUntilChanged' but n
'default' is imported from external module 'rxjs/add/operator/map' but never used
'default' is imported from external module 'rxjs/add/operator/filter' but never used
'default' is imported from external module 'rxjs/add/operator/switchMap' but never used
and when using my library in an application, i get the following warnings:
"export 'default' (imported as 'core_1') was not found in '@angular/core'
Here’s my setup: ng-package.json
{
"$schema": "./node_modules/ng-packagr/ng-package.schema.json",
"src": "lib",
"dest": "dist/lib",
"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"
}
}
}
public_api.ts_
export * from './my-lib/my-lib.module'
tsconfig:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/src",
"baseUrl": "src",
"paths": {
"my-lib": [
"dist/lib"
]
},
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
I haven’t been able to reproduce the issue in an example app and I cannot make any sense of this but I hope you might. Thanks
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 5
- Comments: 28 (8 by maintainers)
I think it’s due to some third party libraries not respecting the Angular Library Format, so the imports you use from the lib, screws with the angular compiler (or webpack).
Here a solution I’ve found to debug, find out which lib breaks the transpilation, and fix the problem.
Suppose I have my-lib project that compiles with ng-packagr into dist/lib folder
After compilation in
dist/lib/my-lib.jsthere is a problem with imports (core is not imported correctly):So one of the imports from TimeAgoPipe library is breaking the compilation
So the solution in this case is to add the entire import path into externals in ng-package.json (if you have other imports from this lib add them too):
After which everything compiles fine:
The most confusing part of this bug is not knowing where the error comes from, because the ng-packagr packages the lib just fine, without warnings or spitting out an error.
For me this happened because I didn’t have my
compilerOptions.moduleset intsconfig.json, which resulted incommonjsbeing used as default (for targetses3ores5).Setting it to
es6fixed it for me.Relevant part:
the top of lib
import core_1, { ApplicationRef, ChangeDetectionStrategy, ChangeDetectorRef, Component, ComponentFactoryResolver, Directive, ElementRef, EventEmitter, Host, HostBinding, HostListener, Inject, Injectable, Injector, Input, NgModule, NgZone, Output, ReflectiveInjector, Renderer, TemplateRef, ViewChild, ViewContainerRef, ViewEncapsulation, forwardRef, isDevMode } from '@angular/core';Thanks for the response @Gandii. I solved it by packaging it using this guide (without ng-packagr) https://www.usefuldev.com/blog/post/publishing-a-library-from-an-angular-cli-project