3

Silly question, but...

Playing around with JHipster 6.6.0, generated a simple monolithic application, started the application with ./gradlew and npm start. Everything seems to work great. Then I added a single line in the src\main\webapp\app\home\home.component.ts file ngOnInit() method:

console.log('Hello, world!');

And I get the following compile error:

ERROR in ./src/main/webapp/app/home/home.component.ts
Module Error (from ./node_modules/thread-loader/dist/cjs.js):

..\src\main\webapp\app\home\home.component.ts
  22:5  error  Unexpected console statement  no-console

✖ 1 problem (1 error, 0 warnings)

Can't compile at all. Only way to get around it is to remove the line altogether, then everything starts working again.

Any ideas why? Perhaps there's a config setting I should change? [I tried adding no-console: false rule to tslint.json, but that didn't make any difference.] Is there a preferred way to add angular/typescript debug statements in JHipster? What am I missing?

Thanks!

[FYI: Development environment is: Windows 10 Pro; IntelliJ 2019.3.2; OpenJDK 13; Node 12.14.1; Gradle 6.0.1; Chrome v79.0.3945.130]

P.S.: I notice the Chrome console is quite busy when running the application, so clearly there must be a way to get messages into the console, but the usual console.log() statement causes a compiler fail!

1 Answer 1

8

Oh, jeez-louise!

Right after I posted my question, I noticed a console.log() statement in the src\main\webapp\app\app.main.ts file, preceded by a curious comment:

// eslint-disable-next-line no-console

I copied/pasted the comment from the src\main\webapp\app\app.main.ts file to the line just before my console.log('Hello, World!') statement, and... hey presto!

Now everything works!

A little esoteric...

Does anyone know: Is this the right way to add console.log() statements in JHipster? Is there a better way? Should I be avoiding console.log() statements altogether? All feedback welcome!

Thanks, again!

Sign up to request clarification or add additional context in comments.

1 Comment

eslint.org/docs/rules/no-console you can disable this rule globally in .eslintrc.json alternatively you can create a log service and ignore this rule only in this service or use an existing one like ngx-logger

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.