Skip to content

ng serve failed: "Cannot find module ... " for all imports starting with "src/" #13860

@HymanZHAN

Description

@HymanZHAN

🐞 Bug report

Command (mark with an x)

- [ ] new
- [ ] build
- [ x ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

I am not sure. Up until I ran npm insatll to update some other dependencies other than angular ones, I did not encounter any problem.

Description

The project was running successfully until I ran npm install to update a few dependencies and resolve some vulnerabilities. Then the project just broke and told me that all the imports starting with src/ failed.

🔬 Minimal Reproduction

I have a tutorial project here. You may just clone it and run ng serve.

🔥 Exception or Error


ERROR in src/app/_services/event.service.ts(6,29): error TS2307: Cannot find module 'src/environments/environment'.
src/app/_services/voter.service.ts(4,29): error TS2307: Cannot find module 'src/environments/environment'.
src/app/events/event-card/event-card.component.ts(2,23): error TS2307: Cannot find module 'src/app/_models/event'.
src/app/events/event-detail/event-detail.component.ts(2,30): error TS2307: Cannot find module 'src/app/_services/event.service'.
src/app/events/event-detail/event-detail.component.ts(4,23): error TS2307: Cannot find module 'src/app/_models/event'.
src/app/events/event-detail/event-detail.component.ts(5,25): error TS2307: Cannot find module 'src/app/_models/session'.
src/app/events/event-list/event-list.component.ts(4,23): error TS2307: Cannot find module 'src/app/_models/event'.
src/app/events/event-new/event-new.component.ts(3,30): error TS2307: Cannot find module 'src/app/_services/event.service'.
src/app/events/event-new/event-new.component.ts(5,23): error TS2307: Cannot find module 'src/app/_models/event'.
src/app/events/event-new/event-new.component.ts(6,40): error TS2307: Cannot find module 'src/app/_validators/location-or-url.validators'.
src/app/events/event-new/event-new.component.ts(7,31): error TS2307: Cannot find module 'src/app/_validators/date.validators'.
src/app/events/event-session-new/event-session-new.component.ts(7,33): error TS2307: Cannot find module 'src/app/_validators/restricted-words.validator'.
src/app/events/event-session-new/event-session-new.component.ts(8,25): error TS2307: Cannot find module 'src/app/_models/session'.
src/app/events/event-session/event-session.component.ts(2,25): error TS2307: Cannot find module 'src/app/_models/session'.
src/app/events/event-session/event-session.component.ts(4,29): error TS2307: Cannot find module 'src/app/_services/auth.service'.
src/app/events/event-session/event-session.component.ts(5,30): error TS2307: Cannot find module 'src/app/_services/voter.service'.
src/app/user/login/login.component.ts(2,29): error TS2307: Cannot find module 'src/app/_services/auth.service'.
src/app/user/login/login.component.ts(4,29): error TS2307: Cannot find module 'src/app/_services/noty.service'.
src/app/user/profile/profile.component.ts(3,29): error TS2307: Cannot find module 'src/app/_services/auth.service'.
src/app/user/profile/profile.component.ts(5,29): error TS2307: Cannot find module 'src/app/_services/noty.service'.

🌍 Your Environment


     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 7.1.0
Node: 10.14.2
OS: win32 x64
Angular: 7.1.1
... animations, common, compiler, core, forms, language-service
... platform-browser, platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.11.0
@angular-devkit/build-angular     0.12.3
@angular-devkit/build-optimizer   0.12.3
@angular-devkit/build-webpack     0.12.3
@angular-devkit/core              7.1.0
@angular-devkit/schematics        7.1.0
@angular/cli                      7.1.0
@angular/compiler-cli             7.1.4
@ngtools/webpack                  7.2.3
@schematics/angular               7.1.0
@schematics/update                0.11.0
rxjs                              6.3.3
typescript                        3.1.6
webpack                           4.28.4

Anything else relevant?
I tried to resolve the issue by fixing the version mismatch between @angular/compiler and @angular/compiler-cli as it was prompted after the npm install, saying that npm WARN @angular/compiler-cli@7.1.4 requires a peer of @angular/compiler@7.1.4 but none is installed. You must install peer dependencies yourself. Not helping at all, if not making things worse...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions