angular-cli: JIT mode only: Uncaught Error: Unexpected value imported by the module 'AppModule'. Please add a annotation.
Bug Report or Feature Request (mark with an x
)
- [x] bug report -> please search issues before submitting
- [ ] feature request
Versions.
@angular/cli: 1.3.0
node: 6.11.0
npm: 5.3.0
os: darwin x64
@angular/animations: 4.3.5
@angular/common: 4.3.5
@angular/compiler: 4.3.5
@angular/core: 4.3.5
@angular/forms: 4.3.5
@angular/http: 4.3.5
@angular/platform-browser: 4.3.5
@angular/platform-browser-dynamic: 4.3.5
@angular/router: 4.3.5
@angular/cli: 1.3.0
@angular/compiler-cli: 4.3.5
@angular/language-service: 4.3.5
Repro steps.
Repository https://github.com/ng-select/ng-select
git clone git@github.com:ng-select/ng-select.git
cd ng-select
npm install
npm run build // should output dist folder
cd integration
npm install // should install @ng-select/ng-select from dist folder
ng serve // will file at runtime
ng serve --prod // works fine
The log given by the failure.
Uncaught Error: Unexpected value 'NgSelectModule' imported by the module 'AppModule'. Please add a @NgModule annotation.
at syntaxError (compiler.es5.js:1690)
at compiler.es5.js:15382
at Array.forEach (<anonymous>)
at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver.getNgModuleMetadata (compiler.es5.js:15365)
at JitCompiler.webpackJsonp.../../../compiler/@angular/compiler.es5.js.JitCompiler._loadModules (compiler.es5.js:26795)
at JitCompiler.webpackJsonp.../../../compiler/@angular/compiler.es5.js.JitCompiler._compileModuleAndComponents (compiler.es5.js:26768)
at JitCompiler.webpackJsonp.../../../compiler/@angular/compiler.es5.js.JitCompiler.compileModuleAsync (compiler.es5.js:26697)
at PlatformRef_.webpackJsonp.../../../core/@angular/core.es5.js.PlatformRef_._bootstrapModuleWithZone (core.es5.js:4536)
at PlatformRef_.webpackJsonp.../../../core/@angular/core.es5.js.PlatformRef_.bootstrapModule (core.es5.js:4522)
at Object.../../../../../src/main.ts (main.ts:11)
Desired functionality.
I expect to serve linked local library without any errors as it works with -aot mode.
Mention any other details that might be useful.
I get this error only then I’m installig local library from dist folder and only with JIT mode. In package.json I have added "@ng-select/ng-select": "../dist/"
It works perfectly fine if I install library from npm repository. I tried to add paths to tsconfig as described here https://github.com/angular/angular-cli/wiki/stories-linked-library but it doesn’t work for me. I would be very helpful if somebody can look at this issue, I thought something may be wrong with my code somewhere but I suppose everything should work fine in JIT mode if it is working in AOT mode 😃
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 4
- Comments: 27 (3 by maintainers)
A lot of these solutions are hacks which seem unpractical, especially when it comes to maintainability. A core/shared library is that way because it holds system critical functionality. I much rather not get used to deleting angular/core folders out of a (or many) library(ies).
I have been trying to follow yeoman’s library seed to properly build a lib (which looks somewhat similar to what @filipesilva is building) as the way to go (to take out my inexperience). But I still run into these issues as described above. It is quite frustrating.
Obviously there are many more out there that have abstracted core code into a lib. A good solution, or a fix, would be welcome. It obviously has to do with the fact that two @angular/* modules are included and therefore the app loads neither (or something like that).
Yes, I could just use 1.2.7 until there is a “golden standard”. But it would also be good to know that this is being addressed (or shown that we are all doing it wrong). So far there is no comment on this thread.
Thanks for building such an awesome tool though. It has helped a ton and is really amazing! I also understand that there are priorities (this may not be one). I don’t want to sound ungrateful.
@amivit
I got the same error Unexpected value ‘MatSnackBar’ imported by the module ‘AppModule’. Please add a @NgModule annotation. at syntaxError (webpack-internal:///…/…/…/compiler/esm5/compiler.js:684)
Just added
in the app module and MatSnackBar in the component the error resolved…
So just for the record: I got it all to work with the latest beta (maybe that is even not necessary). I can confirm the
--preserve-symlinks
and the"paths": {...}
inclusion works. Maybe it helps someone: I figured out my issue was (in the end) that I included too many things in the “paths” object (I was including also non-angular packages, like ngrx, which the lib and the app share).For those still struggling, here is my working setup: note here that the “paths” object goes to the tsconfig of the app which consumes the linked lib (something I was not totally aware of). Check out the core setup with the two tsconfig files (something the yeoman generator did, and which seems to work well).
Maybe this will help someone save some time.
Just wondering if there was a fix for this issue coming up, or if there was a decision in the correct pattern to follow when developing angular libraries?
I’m currently on cli 1.4.2, and I’m having the same issue when using
npm link
to devlop angular libraries, and I have tried the following thingsUnexpected value '[object Object]' imported by the module
ng serve --preserve-symlink
ng serve --aot
I would really appreciate any feedback/guidance. Thanks for all the hard work in building a killer CLI!
A simple reproduction of this issue is available at bgotink/angular-cli-symlink-reproduction
As already mentioned above:
@anjmao I think you’re missing the
paths
in thecompilerOptions
. If I modifyintegration/tsconfig.json
in your repository to matchit works with
@angular/cli@1.2.x
in JIT.