angular - Linking Angular4 Module to Angular4 app: Unexpected value 'TestModule' imported by the module 'AppModule'. Please add a @NgModule annotation -


see further update @ bottom...

i have large app trying convert angular 1.6 angular 4.0. , has become herculean task , stuck @ particular point. have common set of utilities use between 2 different apps. in trying compile module can imported through "npm link" following error upon importing app.

i using webpack 3.

compiler.es5.js:1690 uncaught error: unexpected value 'testmodule' imported module 'appmodule'. please add @ngmodule annotation. @ syntaxerror (compiler.es5.js:1690) @ compiler.es5.js:15382 @ array.foreach (<anonymous>) @ compilemetadataresolver.getngmodulemetadata (compiler.es5.js:15365) @ jitcompiler._loadmodules (compiler.es5.js:26795) @ jitcompiler._compilemoduleandcomponents (compiler.es5.js:26768) @ jitcompiler.compilemoduleasync (compiler.es5.js:26697) @ platformref_._bootstrapmodulewithzone (core.es5.js:4536) @ platformref_.bootstrapmodule (core.es5.js:4522) @ object.<anonymous> (main.ts:26)

i have created test case minimally recreates issue. looks little more complex because left webpack.config , package.json files same real life cases code reduced minimum.

you can see code https://github.com/crowmagnumb/ng-migration-test , steps recreate issue exactly.

my main.ts file in app looks this...

import './polyfills';  import {ngmodule} '@angular/core'; import {browsermodule} '@angular/platform-browser'; import {browseranimationsmodule} '@angular/platform-browser/animations'; import {upgrademodule} '@angular/upgrade/static'; import {platformbrowserdynamic} '@angular/platform-browser-dynamic';  import {testmodule} 'ng-module-test';  @ngmodule({     imports: [         browsermodule,         browseranimationsmodule,         upgrademodule,         testmodule     ] }) export class appmodule {     // override angular bootstrap doesn't     ngdobootstrap() {     } }  // bootstrap using upgrademodule platformbrowserdynamic().bootstrapmodule(appmodule).then(platformref => {     console.log("bootstrapping in hybrid mode angular & angularjs");     const upgrade = platformref.injector.get(upgrademodule) upgrademodule;     upgrade.bootstrap(document.body, ['au.website']); }); 

... , of module looks ...

import {ngmodule} '@angular/core';  import {utils} './utils/module';  @ngmodule({     imports: [         utils     ] }) export class testmodule {}; 

thanks help.

update

i changed import of testmodule relative path instead of loading through linked npm module ...

// import {testmodule} 'ng-module-test'; import {testmodule} '../../ng-module-test/src/main'; 

... , same result. doesn't appear have npm link rather specific separation of code entails. can shed light on that?

i've checked change above repo.

further update

now totally don't understand this. if change import read ...

import {testmodule} './ng-module-test/main'; 

... , make directory called ng-module-test inside of ng-app-test/src , copy contents of ng-module-test/src folder works @hosar kindly discovered in comments. if make symlink using ln -s ../../ng-module-test/src ng-module-test code standpoint of underlying os exact same thing, it doesn"t work.

you need make @angular packages peerdependency , devdependency instead of dependency in ng-module-test/package.json

then add following ng-app-test/src/tsconfig.json:

{   "compileroptions": {     // ...     // note: these paths relative `baseurl` path.     "paths": {       "@angular/*": [         "../node_modules/@angular/*"       ]     }   } } 

see full explanation: https://github.com/angular/angular-cli/wiki/stories-linked-library


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -