I've been trying to export a simple Angular4 module to work in another project for at least a month. Read a lot of articles but it's not working. Here a file containing two folders:
lib -> Containing a simple Angular4 module
demo -> Containing a simple AngularCli project
The lib
is a very simple implementation of an Angular module, and demo
is importing that module inside of its root module.
No matter what I do the demo app gives me different kind of errors saying that the lib
is not an Angular module.
Sometimes talking about not include decorators, and sometimes this error:
ERROR in Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 194:50 in the original .ts file), resolving symbol NgModule
I tried to target es5
and es2015
without any luck.
Steps to reproduce the issue:
download the zip and extract it into a folder
cd
lib
folderrun
npm install
oryarn install
to install the dependenciesrun
npm run bundle
oryarn bundle
to bundle the library intodist
cd
demo
folderrun
npm install
oryarn install
run
npm install ../lib
oryarn add file:../lib
to install the localng-test-lib
which is inside oflib
folderrun
npm start
oryarn start
to start the Demo project
Update:
I add the contents of some of files here:
lib/src/a-module.ts
import { NgModule } from '@angular/core';
import { ADirective } from './a-directive';
@NgModule({
declarations: [
ADirective,
],
exports: [
ADirective,
]
})
export class AModule {}
lib/src/a-directive.ts
import {
Input,
OnInit,
Directive,
} from '@angular/core';
@Directive({
selector: '[aDir]',
})
export class ADirective implements OnInit {
@Input() test: string;
ngOnInit() {
console.log(`I'm the directive, and this is test value: ${this.test}`);
}
}
lib/tsconfig.aot.json
{
"compilerOptions": {
"sourceMap": true,
"inlineSources": true,
"declaration": true,
"noImplicitAny": false,
"skipLibCheck": true,
"stripInternal": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"suppressImplicitAnyIndexErrors": true,
"module": "es2015",
"target": "es5",
"moduleResolution": "node",
"lib": [
"es2015",
"dom"
],
"outDir": "./dist",
"rootDir": "./src",
"baseUrl": ".",
"types": []
},
"files": [
"./src/a-module.ts"
],
"angularCompilerOptions": {
"strictMetadataEmit": true,
"skipTemplateCodegen": true,
"annotateForClosureCompiler": true,
"flatModuleOutFile": "index.js",
"flatModuleId": "index",
"genDir": "./dist"
}
}
Anyone knows what's going on here?