question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Module not found: Error: Can't resolve '@angular/router/src/router'

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior I am trying to build and I get following error: Module not found: Error: Can’t resolve ‘@angular/router/src/router’

Expected behavior Successfull build

Minimal reproduction of the problem with instructions

If the current behavior is a bug or you can illustrate your feature request better with an example, please provide the STEPS TO REPRODUCE and if possible a MINIMAL DEMO of the problem via

import { ActivatedRouteSnapshot } from '@angular/router';
import { DefaultRouteReuseStrategy } from '@angular/router/src/router';

export class CustomRouteReuseStrategy extends DefaultRouteReuseStrategy {

    shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
        let name = future.component && (<any>future.component).name;
        return super.shouldReuseRoute(future, curr) && name !== 'DetailSameComponent';
    }

}

What is the motivation / use case for changing the behavior?

Please tell us about your environment: Windows 10, VS Code, webpack, angular-cli

  • Angular version: 4.0.0

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ] all

  • Language: TypeScript 2.2.2

  • Node (for AoT issues): node --version = 6.9.1

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

16reactions
ichepurnoycommented, Jan 30, 2018

// For latest Angular, like 5.X , you have to update the import strings: I ended up with this service (for which I’m passing data: {reuse: false} in a route config, whenever I need it to work):

import {RouteReuseStrategy} from '@angular/router/';
import {ActivatedRouteSnapshot, DetachedRouteHandle} from '@angular/router';
import {Injectable} from '@angular/core';


export class DefaultRouteReuseStrategy implements RouteReuseStrategy {
    shouldDetach(route: ActivatedRouteSnapshot): boolean { return false; }
    store(route: ActivatedRouteSnapshot, detachedTree: DetachedRouteHandle): void {}
    shouldAttach(route: ActivatedRouteSnapshot): boolean { return false; }
    retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle|null { return null; }
    shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
        return future.routeConfig === curr.routeConfig;
    }
}

@Injectable()
export class CustomRouteReuseStrategy extends DefaultRouteReuseStrategy {
    shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
        const reuse = (future.data && future.data.hasOwnProperty('reuse')) ? future.data.reuse : true;
        return super.shouldReuseRoute(future, curr) && reuse;
    }
}

@ipassynk thanks for sharing the approach!

4reactions
nikolassoarescommented, Feb 20, 2018

try this works wich import { DefaultRouteReuseStrategy } from ‘@angular/router/src/route_reuse_strategy’;

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 2: Module not found: Error: Can't resolve
Try to give relative path instead of absolute one. It will fix the Solution. Like : templateUrl = '../employee/employee.html' in your component.
Read more >
Angular CLI: "Module not found: Error: Can't resolve..."
In this article, I will walk you through how to fix a an error that many people are encountering with Angular CLI 6+....
Read more >
Angular library: Module not found error | by Tanya Gray
This project is an Angular app and Angular library in one project. The app consumes the library directly, not via npm. The error...
Read more >
module not found: error: can't resolve '@angular/router'
Angular CLI looking for router module in wrong place ... ... Dec 5, 2017 ... Failed to compile. ./src/app/app.routing.ts Module not found: Error:...
Read more >
angular/router - npm
Angular - the routing library. Latest version: 15.0.4, last published: 10 days ago. Start using @angular/router in your project by running ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found