Thursday, July 28, 2022

node.js/express: crbug/1173575, non-JS module files deprecated. ... ERR_SSL_PROTOCOL_ERROR

 

>PROBLEM

Attempt to access the site returns the following error messages:


- On browser console:

crbug/1173575, non-JS module files deprecated.


- On browser page:

ERR_SSL_PROTOCOL_ERROR

Não foi possível estabelecer uma conexão segura com este site

Not possible to establish a secure connection with the site





>SOLUTION

Probably you've tried to access the site using https where it should be http.

Ex.:

- wrong:

https://localhost:3000

- because it uses the http protocol service, so:

http://localhost:3000


>ENV

Angular CLI: 13.2.2
Node: 16.13.1
Package Manager: npm 8.5.4
OS: win32 x64

Monday, July 25, 2022

angular: Warning: There are multiple modules with names that only differ in casing. This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.

 

>PROBLEM


The compilation returns the follwing warning message:

  Warning: There are multiple modules with names that only differ in casing.
  This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
  Use equal casing. Compare these module identifiers:


>SOLUTION

Two things to check:

1. If working on Windows, files hasn't case sensitive approach.
So, make sure that the file pointed by the warning message matches case.
If not, remember that it doesn't help renaming the file. It is necessary to rename the file to a different one and then rename it back using the name with the right case.

2. Check the import referred by the error message that it is pointing to the path with different case.
It works on Windows but not on *nix or Mac.
Follow by the images.








Fixed: switched from "_ConfigDb"  to  "_ConfigDB"







>ENV

Angular CLI: 13.2.2
Node: 16.13.1
Package Manager: npm 8.5.4
OS: win32 x64



Sunday, July 24, 2022

angular: is not a known element

 

>PROBLEM

An element is not recognized, returning the following error message:

angular: is not a known element




>SOLUTION

A referencing error may lead to side effects during parsing operation.

The issue is caused by a missing reference that becomes invalid.
It is example happened because the component was deleted using the editor, but it was not able to remove the respective reference together.
It may happen also when you rename or move componets.


Removing the missing references:


the problem is gone.



NOTE:

Errors of @NgModule may lead also to another errors, for instance like NG8002.


>CHECK

>MODULE/SUB-MODULE CONFIG BY IMAGES

Follow by the images how to set up the imports using module and sub-modules through images.











>ENV

Angular CLI: 13.2.2
Node: 16.13.1
Package Manager: npm 8.5.4
OS: win32 x64

Thursday, July 21, 2022

angular: error NG8001: 'pagination-controls' is not a known element



>PROBLEM

 

When angular compiles, returns the following error:

Error: src/app/crud/crud-employee/crud-employee-list/crud-employee-list.component.html:28:11 - error NG8001: 'pagination-controls' is not a known element:

1. If 'pagination-controls' is an Angular component, then verify that it is part of this module.

2. If 'pagination-controls' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.


28           <pagination-controls id="employees_listing_pagination" maxSize="5" directionLinks="true" (pageChange)="page = $event"></pagination-controls>



>SOLUTION

This kind of error message happened when using ngx-bootstrap and some other kind of issue promotes a compilation errors returning eventually this message.

The most common issues were:

1. Malformed module configuration.

2. Non-visible chars resulting in unexpected combinations.

3. Components not declared.


Details at:

Window
Node.js
Angular + ngx-bootstrap

angular or another framework/language: Mysterious compilation errors suddenly appeared after restarting app

 

>PROBLEM

Mysterious compilation errors suddenly appeared after restarting app.
It may happen with any framework/language.

Context:
Everything was done right and the modifications implemented were compiled successfully. Suddenly, after restarting the app, many error messages come from nowhere and they seem not compatible with the code written.




>SOLUTION

When the compilation goes mad, indicates that something outside the project, pertaining to the O.S. system has come to the scene.

Most common causes that occurred to me:
- HD issue
- Corrupted files.
- Non-visible chars (the worst scenario) resulting in unexpected combinations..

The first two causes may be easier to find out.
The third may turn your search into hell.

Through the editor used during the project implementation may not help, because the issue in this cases usually comes transparent to it. For instance, if you are using VS Code (excellent), it will be necessary to use another one to identify the issue, for instance the Notepad++, SciTE, or another one.

In the image below, check the red arrow.
The strange char comes out.

It doesn't help correcting in the editor. The issue may persist because it may have not visible chars during the fix, and they will be still there and may cause more issues.

The best thing to do is to create a new file and retype the code.
You may risk doing just this with just the defective line.
Better if you replace all the code from another source or manually.


This kind of issue happened to me three times and the first one drove me crazy.


>VERSIONING CONTROL  SIDE EFFECTS (Git, etc.)

The versioning is also affected.
The best approach, because it is faster and more effective, is:

1. Copy the current code to a temporary folder.
2. Checkout to a previous version — the most recent state that compiles successfully.
3. Replace the differences without copying, otherwise, you may contaminate the content again.

NOTE:
Non-visible chars produce issues to the compiler and also to any other software working with the files, and that is the case of the versioning control, spoiling the merges.

>ENV

Windows
Node.js
Angular 12 and higher.



Wednesday, July 20, 2022

angular: Error: node_modules/ngx-bootstrap/modal/bs-modal.service.d.ts:7:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

 


>PROBLEM

Angular compilation throws the following error:

Error: node_modules/ngx-bootstrap/modal/bs-modal.service.d.ts:7:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (ngx-bootstrap/modal) which declares BsModalService has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.


>SOLUTION

>BEFORE (WRONG)

imports: [

BsModalService,

],

providers: [

],


>AFTER (RIGHT)

imports: [

BsModalService,

],

providers: [

BsModalService,

],




>ENV

Angular CLI: 13.2.2

Node: 16.13.1

Package Manager: npm 8.5.4

OS: win32 x64


angular: Error: node_modules/ngx-bootstrap/datepicker/bs-datepicker.config.d.ts:8:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

 

>PROBLEM

Angular compilation returns:

Error: node_modules/ngx-bootstrap/datepicker/bs-datepicker.config.d.ts:8:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.


This likely means that the library (ngx-bootstrap/datepicker) which declares BsDatepickerConfig has not been processed correctly by ngcc, or is not compatible with Angular Ivy. 

Check if a newer version of the library is available, and update if so. 

Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy. 



>SOLUTION


Edit app.module.ts and fix its configuration as follows:


>BEFORE (WRONG)

  imports: [

AlertConfig, 

BsDropdownConfig, 

BsDatepickerConfig

  ],

  providers: [],


>AFTER (RIGHT)

  imports: [

  ],

  providers: [AlertConfig, BsDropdownConfig, BsDatepickerConfig],



>ENV

Angular CLI: 13.2.2

Node: 16.13.1

Package Manager: npm 8.5.4

OS: win32 x64


Thursday, July 14, 2022

angular: ngForm: error NG8002: Can't bind to 'formControl' since it isn't a known property of 'input'.

 

>PROBLEM

After adding an implementation to bind using ngModel , for instance:

    <label for="example-ngModel">[(ngModel)]:</label>

    <input [(ngModel)]="currentItem.name" id="example-ngModel">


Running angular using ngModels, returns the error message:

error NG8002: Can't bind to 'ngModel' since it isn't a known property of 'input'
Can't bind to 'formGroup' since it isn't a known property of 'form'

Error: src/app/crud/crud-employee/crud-employee-update/crud-employee-update.component.html:2:9 - error NG8002: Can't bind to 'formGroup' since it isn't a known property of 'form'.

2   <form [formGroup]="updateForm" (ngSubmit)="saveToList(updateForm)">


For instance, implementing a simple example like this:




You get:




Another example:



>SOLUTION


@NgModule is a key concern in Angular.

This NG8002 error usually comes from the @NgModule misconfiguration (missing something).
For instance, a usual occurrence may happen with these scenarios:

1. A new module is created and not registered on app.module.ts.
or

2. A new component is created and not registered in its specific module.
or

3. The selector's module is not registered in the module.

The selector is that declared in the .ts file, for instance at:
@Component({
  selector: 'app-modal-list',

Referenced in the .html file comes like this:
<app-modal-list></app-modal-list>



There are a few things to be observed.


1. Requires modules setup.

Set the required modules in app.modules.ts. Example:


import { FormsModule, ReactiveFormsModule } from "@angular/forms";

...

@NgModule({

  declarations: [
        //...
   ],

  imports: [
//...
    FormsModule,
    ReactiveFormsModule,
  ],


*** IMPORTANT NOTE:

If you are using a page under its specific module, declare in that module too.

Example:

app
+--forms-lab
+-- forms1
--- forms-lab.module.ts


Edit forms-lab.module.ts and declare both modules referred to above.


2. Make sure that you have not overwritten the angular modules: 

It is something easy to happen, for instance, if you create a module called forms, as it is:


ng g m forms


This command will generate a FormsModule that overrides the angular's module.
This conflict causes the same issue.

If it happened, delete, and recreate it with another name.


3. Check if all components are declared in its modules.ts file.

Using the example above, it would be something like this in the forms-lab.module.ts file:

import { Forms1Component } from './forms1/forms1.component';
...
@NgModule({
  declarations: [
    Forms1Component,
  ],


4. Check if there isn't naming conflict.

Sometimes, the way the components are named may cause the issue.

Check the following image:




@MORE: 

https://stackoverflow.com/questions/43220348/cant-bind-to-formcontrol-since-it-isnt-a-known-property-of-input-angular


>ENV

Angular CLI: 13.2.2

Node: 16.13.1

Package Manager: npm 8.5.4

OS: win32 x64


Friday, July 8, 2022

node.js: express: req.session returns "undefined"

 

>PROBLEM

node.js: express: req.session returns "undefined".

console.log(req.session)

- Returns:

undefined


>SOLUTION

The session block declaration shall come before the routing blocks.


>>BEFORE

// error handler
app.use(function (err, req, res, next) {
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};
  res.status(err.status || 500);
  res.render('error');
});

// ...

const session = require('express-session');
app.set('trust proxy', 1) // trust first proxy
app.use(session({
    secret: ConfigSvc.configValue('sessionKey'),
    saveUninitialized:true,
    cookie: { maxAge: oneDay, secure: true },
    resave: false
}));


>>AFTER

var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var todoRouter = require('./routes/todo');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({
  extended: false
}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

var favicon = require('serve-favicon');
const ConfigSvc = require('./utils/ConfigSvc');
app.use(favicon(__dirname + '/public/favicon.ico'));

const oneDay = 8640000;
const session = require('express-session');
app.set('trust proxy', 1) // trust first proxy
app.use(session({
    secret: ConfigSvc.configValue('sessionKey'),
    saveUninitialized:true,
    cookie: { maxAge: oneDay, secure: true },
    resave: false
}));

app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/todo', todoRouter);

// catch 404 and forward to error handler
app.use(function (req, res, next) {
  next(createError(404));
});


// error handler
app.use(function (err, req, res, next) {
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};
  res.status(err.status || 500);
  res.render('error');
});


>ENV

Node.js 16
Express
JWT

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...