mgechev / mgechev/aspect.js

Getting Error while implementing AspectJs in angular8

Open
#81 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
470
Forks
37
PR merge metrics
No merged PRs in 30d

Description

I am trying to implement aspectjs with Angular 8. I've added below code but while running the application I am getting below error.

Uncaught Error: Unexpected value 'result' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@Component annotation.
at syntaxError (compiler.js:2175)
at flattenAndDedupeArray.forEach (compiler.js:19710)
at Array.forEach ()
at CompileMetadataResolver.getNgModuleMetadata (compiler.js:19692)
at JitCompiler._loadModules (compiler.js:25402)
at JitCompiler._compileModuleAndComponents (compiler.js:25385)
at JitCompiler.compileModuleAsync (compiler.js:25347)
at CompilerImpl.compileModuleAsync (platform-browser-dynamic.js:216)
at compileNgModuleFactory__PRE_R3__ (core.js:31350)
at PlatformRef.bootstrapModule (core.js:31655)

Below is the code which I am using to implement aspectjs.

aspectjs.ts code:

`import {beforeMethod, afterMethod, Metadata} from 'aspect.js';
import { Injectable } from '@angular/core';

@Injectable()
export class LoggerAspect {
public static loggerService:LoggerService;

@beforeMethod({
classNamePattern: /^.*/,
methodNamePattern: /^.*/
})
static invokeBeforeMethod(meta:Metadata):void {
let message:string = `method: ${meta.method.name}, args: ${meta.method.args.join(', ')}`;
console.log(message);
}
}

export class LoggerService{
value:string
}`

AppModule Code:

`export class AppModule {
constructor(private loggerService:LoggerService) {
LoggerAspect.loggerService = loggerService;
}
}`

component.ts code:
`import { Component, Injectable } from '@angular/core';
import { Wove } from "node_modules/aspect.js-angular";

@Wove()
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})

export class AppComponent {
}
`
When I am removing @Wove from component.ts then application is working fine however getting error when adding it again.

I've gone through https://github.com/mgechev/aspect.js/issues/29. but was not able to resolve it.

Any help or guidance will be appreciated.

Thanks

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the failure with @Wove() in component.ts and inspect how aspect.js-angular integrates with AppModule and the Angular 8 compiler. Compare the setup with the referenced aspect.js issue, focusing on why `result` is reported as an invalid AppModule declaration. Done means the application compiles and runs with @Wove() enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.