Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular CLI looking for router module in wrong place? "router_module not found"

I have an issue:

Based on the trace, my code is looking for the router module in the wrong place, it should be looking in my node modules\@angular folder but its looking in my src\app\ folder, how can i fix this?

How I got here

I've installed angular 2 using angular cli, when I go to use the router module to create my routes, I import it like so:

import { RouterModule } '@angular/router/src/router_module';

and then use it passing in my routes like so:

export const routing = RouterModule.forRoot(APP_ROUTES, {enableTracing: true});

now when it goes to compile i get the following error:

Failed to compile.

./src/app/app.routing.ts Module not found: Error: Can't resolve

'@angular/router/src/router_module' in 'C:\path\to\src\app' <== important part ?

@ ./src/app/app.routing.ts 3:0-84

@ ./src/app/app.module.ts

@ ./src/main.ts

@ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts

I've checked that node module/@angular/router/src/router_module exists, and it does... I'm really stumped

angluar cli v1.0.1

angular v 4.4.6

like image 647
Jay Avatar asked May 02 '26 23:05

Jay


1 Answers

Use this as your import:

import { RouterModule } from '@angular/router';

Get rid of the /src/router_module on the end of the path, and don't forgot the from.

I don't know what IDE you are using, but I use VS Code. Sometimes, when I use the Ctrl+. (control period) to get the IDE to add a reference for me, I get some extra stuff in the path like what you had.

Something to watch out for!

like image 193
R. Richards Avatar answered May 05 '26 13:05

R. Richards