angular-cli: Error encountered resolving symbol values statically
Please provide us with the following information:
OS?
Mac OSX (El Capitan)
Versions.
@angular/cli: 1.0.0-beta.30 node: 7.0.0 os: darwin x64 @angular/common: 2.4.6 @angular/compiler: 2.4.6 @angular/core: 2.4.6 @angular/forms: 2.4.6 @angular/http: 2.4.6 @angular/platform-browser: 2.4.6 @angular/platform-browser-dynamic: 2.4.6 @angular/router: 3.4.6 @angular/cli: 1.0.0-beta.30 @angular/compiler-cli: 2.4.6
Repro steps.
Added a simple Opaque Token and NG-BUILD failed as the PROVIDER
import { OpaqueToken } from '@angular/core';
export const SUMMARRY = new OpaqueToken('summary');
const dictionary = { };
// providers
export const SUMMARY_PROVIDER =
[
{ provide: SUMMARY, useValue: dictionary },
];
The log given by the failure.
ERROR in Error encountered resolving symbol values statically. Reference to a local (non-exported) symbol ‘dictionary’. Consider exporting the symbol (position 14:7 in the original .ts file), resolving symbol SUMMARY_PROVIDERS
Any other information
To workaround this:
- I put the dictionary inside a single quotes
- Ran
ng-build
and thenng-serve
- The code failed as it is now a string
- Went back to code and removed the single quotes
- Webpack did not complain and the code works fine
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 22 (7 by maintainers)
I have the same issue:
Package A has an InjectionToken T defined in it. Package B depends on Package A. It uses token T in the providers as follows:
{ provide: TokenT, useValue: SampleValue }
I bundle Package A using WebPack. The error is thrown that TokenT is not statically analyzable, and I must use initialized variables or constants. If I define TokenT in PackageB (not from an external package) then the error is resolved. Is there a way to either disable static analyzing or allow InjectionTokens to be used across multiple packages? Any ideas how to solve that issue?
Export dictionary and the error should go away
@TheDocX thanks, it seems to be the same as mine but I found the solution in here: http://stackoverflow.com/questions/41932998/angular-2-error-encountered-resolving-symbol-values-statically
I got the same
Error encountered resolving symbol values statically
.The error disappeared when I removed the type information: