angular: ng serve fails with "ERROR in Debug failure: no local name provided for NamespaceImport"
🐞 Bug report
Command (mark with an x
)
- new
- build
- serve
- test
- e2e
- generate
- add
- update
- lint
- xi18n
- run
- config
- help
- version
- doc
Is this a regression?
Yes, the same app was working with Angular 8 and CLI 8.
Description
A clear and concise description of the problem...Running ng serve consistently fails with the stack trace reported below.
🔬 Minimal Reproduction
npm install ng serve It’s a private repo and the exception does not refer to any specific code in the repo. It seems to be a generic error in compiler-cli itself.
🔥 Exception or Error
ERROR in Debug failure: no local name provided for NamespaceImport
F:\webstr\node_modules\@angular\compiler-cli\src\ngtsc\core\src\compiler.js:342
finally { if (e_2) throw e_2.error; }
^
Error: Debug failure: no local name provided for NamespaceImport
at extractModuleAndNameFromImport (F:\webstr\node_modules\@angular\compiler-cli\src\ngtsc\reflection\src\type_to_value.js:173:27)
at Object.typeToValue (F:\webstr\node_modules\@angular\compiler-cli\src\ngtsc\reflection\src\type_to_value.js:59:28)
at F:\webstr\node_modules\@angular\compiler-cli\src\ngtsc\reflection\src\typescript.js:76:58
at Array.map (<anonymous>)
at TypeScriptReflectionHost.getConstructorParameters (F:\webstr\node_modules\@angular\compiler-cli\src\ngtsc\reflection\src\typescript.js:55:36)
at Object.getConstructorDependencies (F:\webstr\node_modules\@angular\compiler-cli\src\ngtsc\annotations\src\util.js:32:36)
at extractInjectableCtorDeps (F:\webstr\node_modules\@angular\compiler-cli\src\ngtsc\annotations\src\injectable.js:233:38)
at InjectableDecoratorHandler.analyze (F:\webstr\node_modules\@angular\compiler-cli\src\ngtsc\annotations\src\injectable.js:71:31)
at TraitCompiler.analyzeTrait (F:\webstr\node_modules\@angular\compiler-cli\src\ngtsc\transform\src\compilation.js:341:40)
at analyze (F:\webstr\node_modules\@angular\compiler-cli\src\ngtsc\transform\src\compilation.js:293:58)
🌍 Your Environment
Angular CLI: 9.0.5
Node: 12.13.1
OS: win32 x64
Angular: 9.0.5
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.900.5
@angular-devkit/build-angular 0.900.5
@angular-devkit/build-optimizer 0.900.5
@angular-devkit/build-webpack 0.900.5
@angular-devkit/core 9.0.5
@angular-devkit/schematics 9.0.5
@angular/cdk 9.1.2
@angular/material 9.1.2
@ngtools/webpack 9.0.5
@schematics/angular 9.0.5
@schematics/update 0.900.5
rxjs 6.5.4
typescript 3.7.5
webpack 4.41.2
Anything else relevant?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 5
- Comments: 21 (11 by maintainers)
Commits related to this issue
- fix(compiler): handle type references to namespace imports correctly When the compiler needs to convert a type reference to a value expression, it has to deal with various import forms one of which i... — committed to JoostK/angular by JoostK 4 years ago
- fix(compiler): handle type references to namespace imports correctly When the compiler needs to convert a type reference to a value expression, it has to deal with various import forms one of which i... — committed to JoostK/angular by JoostK 4 years ago
- fix(compiler): handle type references to namespace imports correctly When the compiler needs to convert a type reference to a value expression, it has to deal with various import forms one of which i... — committed to JoostK/angular by JoostK 4 years ago
- fix(compiler): handle type references to namespace imports correctly When the compiler needs to convert a type reference to a value expression, it has to deal with various import forms one of which i... — committed to JoostK/angular by JoostK 4 years ago
- fix(compiler): handle type references to namespaced symbols correctly When the compiler needs to convert a type reference to a value expression, it may encounter a type that refers to a namespaced sy... — committed to JoostK/angular by JoostK 4 years ago
- fix(compiler): handle type references to namespaced symbols correctly When the compiler needs to convert a type reference to a value expression, it may encounter a type that refers to a namespaced sy... — committed to JoostK/angular by JoostK 4 years ago
- fix(compiler): handle type references to namespaced symbols correctly When the compiler needs to convert a type reference to a value expression, it may encounter a type that refers to a namespaced sy... — committed to JoostK/angular by JoostK 4 years ago
- fix(compiler): handle type references to namespaced symbols correctly When the compiler needs to convert a type reference to a value expression, it may encounter a type that refers to a namespaced sy... — committed to JoostK/angular by JoostK 4 years ago
- fix(compiler): handle type references to namespaced symbols correctly When the compiler needs to convert a type reference to a value expression, it may encounter a type that refers to a namespaced sy... — committed to JoostK/angular by JoostK 4 years ago
- fix(compiler): handle type references to namespaced symbols correctly When the compiler needs to convert a type reference to a value expression, it may encounter a type that refers to a namespaced sy... — committed to JoostK/angular by JoostK 4 years ago
- fix(compiler): handle type references to namespaced symbols correctly (#36106) When the compiler needs to convert a type reference to a value expression, it may encounter a type that refers to a name... — committed to angular/angular by JoostK 4 years ago
@Maximaximum It’s been merged into the 9.1.x branch just after the release of 9.1.1, so it will be included in 9.1.2 next week. Releases typically go out on Wednesdays.
@Maximaximum This is definitely a bug in the compiler. The compiler attempts to convert the
MemoryStorage
type declaration (for thememoryStorage
parameter in the constructor) to a value expression that is used as DI token. In this case, it doesn’t know how to handle the namespace import (it’s actually invalid to refer toMemoryStorage
as a value, the workaround using"allowSyntheticDefaultImports"
is then required to expressMemoryStorage
as a value), so it throws.However, the type-to-value conversion is irrelevant in this case because there an explicit DI token provided using the
@Inject
decorator. As such, the compiler should not crash when it fails to convert a type to a value, as that may be handled using an@Inject
decorator.@avoliva Ah, excellent thanks for the details. The default import seems like the proper workaround here. The namespace import like
import * as Rollbar from 'rollbar';
cannot be used as a value (which Angular’s DI system requires) as TypeScript would then complain:In this particular case however, the usage of
@Inject
makes the type-to-value conversion irrelevant as an explicit token is provided, so it looks like we should not be throwing that error at all. I experimented with that change in the compiler and this would properly produce a diagnostic if@Inject
is omitted andstrictInjectionParameters
is enabled:@avoliva This was the exact same issue for me. My project is also using rollbar. Thanks for the tip, the code does compile now.
Now, from an Angular 9 perspective, it still looks like a regression because that code worked with Angular 8.
The only change I had to make was making my import of Rollbar from
import * as Rollbar from 'rollbar'
toimport Rollbar from 'rollbar'
After that, I added
"allowSyntheticDefaultImports": true
to the compiler options in my tsconfig file.