[AoT] can't resolve all parameters for [lib] in [lib].d.ts: (?, ?, ?)
See original GitHub issueType of Issue
[x] Bug Report
[ ] Feature Request
Description
I can compile my lib successfully with ng-packagr
(version 1.6
) and I then published it to NPM and it’s all good. Except when I’m trying to compile the external app as AOT/Prod, I get the following error:
ERROR in Error: Can't resolve all parameters for AngularSlickgridComponent in C:/sourcecode/Angular-Slickgrid-PackageTest/node_modules/angular-slickgrid/angular-slickgrid.d.ts: (?, ?, ?, ?, ?, ?).
at syntaxError (C:\sourcecode\Angular-Slickgrid-PackageTest\node_modules\@angular\compiler\bundles\compiler.umd.js:1729:34)
at CompileMetadataResolver._getDependenciesMetadata (C:\sourcecode\Angular-Slickgrid-PackageTest\node_modules\@angular\compiler\bundles\compiler.umd.js:15816:35)
at CompileMetadataResolver._getTypeMetadata (C:\sourcecode\Angular-Slickgrid-PackageTest\node_modules\@angular\compiler\bundles\compiler.umd.js:15684:26)
at CompileMetadataResolver.getNonNormalizedDirectiveMetadata (C:\sourcecode\Angular-Slickgrid-PackageTest\node_modules\@angular\compiler\bundles\compiler.umd.js:15279:24)
at CompileMetadataResolver.loadDirectiveMetadata (C:\sourcecode\Angular-Slickgrid-PackageTest\node_modules\@angular\compiler\bundles\compiler.umd.js:15141:25)
at C:\sourcecode\Angular-Slickgrid-PackageTest\node_modules\@angular\compiler\bundles\compiler.umd.js:15380:54
at Array.forEach (<anonymous>)
at CompileMetadataResolver.loadNgModuleDirectiveAndPipeMetadata (C:\sourcecode\Angular-Slickgrid-PackageTest\node_modules\@angular\compiler\bundles\compiler.umd.js:15379:41)
at C:\sourcecode\Angular-Slickgrid-PackageTest\node_modules\@angular\compiler\bundles\compiler.umd.js:23799:99
at Array.map (<anonymous>)
at AotCompiler.analyzeModulesAsync (C:\sourcecode\Angular-Slickgrid-PackageTest\node_modules\@angular\compiler\bundles\compiler.umd.js:23799:42)
at CodeGenerator.codegen (C:\sourcecode\Angular-Slickgrid-PackageTest\node_modules\@angular\compiler-cli\src\codegen.js:32:14)
at Function.NgTools_InternalApi_NG_2.codeGen (C:\sourcecode\Angular-Slickgrid-PackageTest\node_modules\@angular\compiler-cli\src\ngtools_api.js:73:30)
at _donePromise.Promise.resolve.then (C:\sourcecode\Angular-Slickgrid-PackageTest\node_modules\@angular\cli\node_modules\@ngtools\webpack\src\plugin.js:386:44)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
How To Reproduce
Install my lib, Angular-Slickgrid from NPM and try to compile in AOT, you will get the error shown on top. You can also see the dist folder of the ng-packagr
compilation (which is run through ng-packagr -p ng-package.json
). I also know that the (?, ?, ?, …) are the Services dependency injections, but I don’t know why it only shows up in AOT compilation
I am fairly new to Angular 4+ (just a couple months since I started) and I’m confused with all these JIT, AOT, … and I don’t know what could be the problem or where to look. The search that I have done brings nowhere, I thought it was cyclical dependencies as shown here but it can’t be it since showCyclicalDependencies
is enabled by default in Angular-CLI since 1.3
. I believe that I have this problem since long time but it works all good in Dev environment, it’s really just AOT that fails.
Any help is appreciated, I really need to resolve this issue.
Expected Behaviour
No error thrown
Version Information
ng-packagr: 1.6.0
@angular/*: 4.x.x
typescript: 2.3.4
rxjs: 5.4.2
node: 8.70
npm: 5.4.1
please include any version information that might be relevant, e.g. other third-party libraries
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:11 (4 by maintainers)
Top GitHub Comments
Ah ok sure, see below for what I think were the errors in my case
1- I had an
index.ts
with export of all my Services.index.ts
from Services folder2- Inside my lib component, I was calling in a 1 liner all my Services
import
to call the Services 1 by 1So I think the number 2) is what caused the
can't resolve all parameters for [lib] in [lib].d.ts: (?, ?, ?, ?, ?, ?)
There is no longer duplicates export in myd.ts
file and the DI is working as expected.I had other errors to fix after but I don’t think they are related at all to the original problem, so I won’t post them here unless you want to see them too.
For me, the issue is that I was importing from the barrel, instead of directly from the files.
Check your
my-module.d.ts
file in the library distributable directory, in my case it was inside/dist/lib
.If you see any exports in addition to
export * from './public_api';
, and./public_api
also exports those same exports; that is the cause of your issue. To stop these exports from being exported twice, you’ll need to remove all imports from barrels inside your library.Example
A simple Find-all for the ending of my barrel path
myModule';
showed me all occurrences of where I was importing from the barrel; then I simply expanded these imports to import each file independently.Before
After