Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No provider for Router! Angular 12 Matomo 1.0.0-rc.1 #58

Open
dtomaszewski opened this issue Jun 7, 2021 · 21 comments
Open

No provider for Router! Angular 12 Matomo 1.0.0-rc.1 #58

dtomaszewski opened this issue Jun 7, 2021 · 21 comments
Assignees
Labels
bug Something isn't working dependencies Pull requests that update a dependency file
Projects
Milestone

Comments

@dtomaszewski
Copy link

dtomaszewski commented Jun 7, 2021

Hi,

I have issue with routeTracking functionality in Angular 12, when I enable it to true like in README file all I get is missing Router provider error.

My deps are:

"dependencies": { "@angular-devkit/schematics": "12.0.2", "@angular/animations": "^12.0.0", "@angular/cdk": "^12.0.2", "@angular/common": "^12.0.0", "@angular/compiler": "^12.0.0", "@angular/core": "^12.0.0", "@angular/forms": "^12.0.0", "@angular/material": "^12.0.2", "@angular/platform-browser": "^12.0.0", "@angular/platform-browser-dynamic": "^12.0.0", "@angular/router": "^12.0.0", "@angular/upgrade": "^12.0.0", ... "ngx-matomo": "^1.0.0-rc.1", ... }

When routeTracking is set to false everything looks fine. I've also tried to set it to false and run MatomoRouteTracker startTracking method manually at later point but it's the same issue.

It occurs for lazy loading routes.

@Arnaud73 Arnaud73 self-assigned this Jun 7, 2021
@Arnaud73 Arnaud73 added the bug Something isn't working label Jun 7, 2021
@Arnaud73 Arnaud73 added this to the Release 1.0 milestone Jun 7, 2021
@Arnaud73
Copy link
Owner

Arnaud73 commented Jun 8, 2021

I did not test it yet. I was pretty sure it would work the same.
I'm going to try to reproduce this issue.
Stay tuned :)

@Arnaud73
Copy link
Owner

I made some tests with my demo application and so far, it's working correctly.

Can you explain me how you load the router and ngx-matomo modules in your app?

@khaled4vokalz
Copy link

khaled4vokalz commented Aug 6, 2021

I also get the same error when the AppModule doesn't use RouterModule and uses UIRouterModule.

Seems like someone else also facing this error #65

@dtomaszewski
Copy link
Author

Hello, is there any progress here?

@mredaelli
Copy link

Same error after upgrading to angular 15. We use yarn, will try npm (see #65 (comment) )

@RomainFALLER
Copy link

Same error if you install the library using yarn.

@Arnaud73
Copy link
Owner

I'll try to reproduce this error. It's not quite common, but too many people suffer from it!
@RomainFALLER, can you provide me with your package.json file (at least the dependencies)? Also, are you working on Windows, macOS or Linux?

@Arnaud73 Arnaud73 added the dependencies Pull requests that update a dependency file label Jul 10, 2023
@Arnaud73 Arnaud73 added this to In progress in ngx-matomo Jul 10, 2023
@RomainFALLER
Copy link

RomainFALLER commented Jul 12, 2023

Hello,

Here are my dependencies :
"@angular/animations": "15.2.1",
"@angular/common": "15.2.1",
"@angular/compiler": "15.2.1",
"@angular/core": "15.2.1",
"@angular/forms": "15.2.1",
"@angular/platform-browser": "15.2.1",
"@angular/platform-browser-dynamic": "15.2.1",
"@ngrx/effects": "15.3.0",
"@ngrx/store": "15.3.0",
"@ngrx/store-devtools": "15.3.0",
"@sentry/angular-ivy": "^7.56.0",
"ngx-matomo": "^1.1.0",
"powerbi-client-angular": "^3.0.5",
"rxjs": "~7.8.0",
"tslib": "^2.5.0",
"zone.js": "~0.13.0"

Also, we are working on Windows.

I did the test again and I can confirm.

add ngx-matomo: 1.1.0 to package.json
yarn install
yarn start
--> error

rm -rf nodes_module/ngx-matomo
npm install ngx-matomo -f
yarn start
--> OK

@bastienjalbert
Copy link

Hello, I encounter the same issue using yarn as package manager. Looks to work with npm, but I use yarn everywhere.

@Arnaud73
Copy link
Owner

I shall now be able to reproduce. This might be an issue the optionalDepency as indicated in the package.json file of ngx-matomo.

@Arnaud73
Copy link
Owner

Hello, I encounter the same issue using yarn as package manager. Looks to work with npm, but I use yarn everywhere.

I also use yarn for all of my private projects, however, each and every Angular App I have is using the Angular Router, so I guess, I am in the sweet spot for not having any problem.

@Arnaud73
Copy link
Owner

@bastienjalbert or @RomainFALLER, I guess I found my mistake. I can build an updated version of the 2.0 or 1.1 version with this fix and send it directly to you for testing since I don't want to publish a test package on the NPM registry. All you would need to do is tell me which version you want patched (1.1 or 2.0), receive the TAR file, decompress it to your drive, modify your package.json file to update the ngx-matomo dependency and test. Who's in?

@RomainFALLER
Copy link

Let's do it.
The application I am working on is in Angular 15 so I prefer the version 1.1.
You can send it by mail : romain.faller@gmail.com.

I will test it and let you know the result.

Thank you.

@bastienjalbert
Copy link

Hi @Arnaud73, may you push the branch with your modifications ? That way I'll build the package in local and try your fix.

@Arnaud73
Copy link
Owner

@bastienjalbert, the branch is fix/yarn_incompatibility, it is dedicated for ngx-matomo 2.0. If you want to backport it to version 1.1 cherrypick the commit and apply it on top of the commit you chose based on its tag. Don't forget to change the versions so does it does not look for Angular 16.
In order to build the library, just run npm run build:ngx-matomo:prod, the library will be in the dist folder

@RomainFALLER
Copy link

@Arnaud73 I followed the steps below :

  1. Cherry pick the last commit on the version 1.1.0 (adapt the change of package.json with the one of 1.1.0).
  2. yarn build
  3. yarn pack --> the command generated a ngx-matomo-v1.1.0.tgz
  4. Add ngx-matomo-v1.1.0.tgz in the file package.json of my project
  5. yarn install in my project

I still have the error No provider for ActivatedRouter...
In my project, I have this dependency :
"@angular/router": "15.2.1"

The package.json of the ngx-matomo I am using is the one bellow:
package.json.txt

If I delete ngx-matomo and install with npm install ngx-matomo -f, it works withtout modifying my package.json.

If I modify my package.json with this, it works with yarn :
"@angular/router": "^15.2.1" instead of "@angular/router": "15.2.1"

Thank you.

Romain

@Arnaud73
Copy link
Owner

Too bad it does not work (however I think I will keep this modification).
I'm going to make a dedicated app to try to reproduce it.
@RomainFALLER, is there any additional indication of where the exception occurs in your code?

@RomainFALLER
Copy link

RomainFALLER commented Jul 25, 2023

Here is the stack :
image

Also, I tested with @angular/router 15.2.9 and it works...

I will provide you other information if needed.

@Arnaud73
Copy link
Owner

Thanks @RomainFALLER!

I think I know my mistake. With the previous declaration of optional dependencies, @angular/router was not really optional for npm but was for yarn (and also a warning message during installation), thus was installed by npm and then the ActivatedRoute was available. Since I fixed the declaration of dependencies, neither npm nor yarn is installing @angular/router and as a result, ngx-matomo cannot access ActivatedRoute, thus resulting in an error when trying to work without the @angular/router.

Basically, I thought I was able to make the module work without @angular/router when no route tracking was activating, but my solution was not OK since the @angular/router was installed anyway, even when I was not asking for it.
I'll check the best practices for having optional dependencies in the code, but for the moment, I guess I will have to create another entry point in the library with a different definition of the library. You may need to change your import {…} from 'ngx-matomo' to import {…} from 'ngx-matomo/routerless' in order to use modules and services without a dependency to @angular/router.

Stay tuned, I'll post an update to my findings.

@RomainFALLER
Copy link

Thank you, very interesting.

I am waiting for your modifications :). However, you don't mention any connection with a possible version of the package @angular/router, so how can we explain the different behaviours regarding the version (15.2.1 vs 15.2.9 for example) ?

@Nek-
Copy link

Nek- commented Aug 8, 2023

I have the same error as @RomainFALLER on the latest version of the package and angular 16.1. angular/router is installed and should work as expected... I have no idea what I did wrong. I ended up removing the package... And I have no workaround sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file
Projects
ngx-matomo
In progress
Development

No branches or pull requests

7 participants