question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[AoT] can't resolve all parameters for [lib] in [lib].d.ts: (?, ?, ?)

See original GitHub issue

Type 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:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

13reactions
ghiscodingcommented, Dec 13, 2017

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.

  • deleted the index.ts from Services folder

2- Inside my lib component, I was calling in a 1 liner all my Services

  • changed import to call the Services 1 by 1
-import { ControlAndPluginService, FilterService, GridEventService, GridExtraService, SortService, ResizerService } from './../services';
+import { ControlAndPluginService } from './../services/controlAndPlugin.service';
+import { FilterService } from './../services/filter.service';
+import { GridEventService } from './../services/gridEvent.service';
+import { GridExtraService } from './../services/gridExtra.service';
+import { ResizerService } from './../services/resizer.service';
+import { SortService } from './../services/sort.service';

So 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 my d.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.

7reactions
trentrandcommented, Dec 29, 2017

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

import { MenuService, MenuItem } from '../menu-service';

After

import { MenuService } from '../menu-service/menu.service';
import { MenuItem } from '../menu-service/menu-item';
Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular cli 2 Error Can't resolve all parameters for XXXXX by ...
1 Answer 1 · Thank for your answer. For the ProgramService and CacheService can be resolved. but other array parameter cannot be resovled....
Read more >
Angular compiler options
When you use ahead-of-time compilation (AOT), you can control how your application is compiled by specifying template compiler options in the TypeScript ...
Read more >
angular/angular - Gitter
I have a component that expects it to be injected, but I can't seem to mock it or ... causes this error: Error:...
Read more >
Set Up Your ngUpgrade Project for Production Without Crying ...
Getting the AOT compiler to work requires we have a hard separation between our AngularJS code and our Angular code. This requires two...
Read more >
Can't build my project : r/Angular2 - Reddit
If I run ng build, it works fine. If I try to run ng build --prod or ng build --aot, when it finishes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found