TS2307: Cannot find module (all modules) - after moving folders

时间:2018-09-18 20:24:44

标签: angular npm build angular-components angular-module

I decided to moving folders in order to organize modules as follows: Structure of catalogs

Automatically was changed app.module.ts:

app.module.ts with important part of debug.log

But, when I try to use npm install or ng serve I get:

ERROR in : Can't resolve all parameters for EmployeesComponent in C:/Users/admin/Desktop/erp-mes-frontend/src/app/staff/employees/employees/employees.component.ts: (?, [object Object]).
src/app/staff/employees/employees/employees.component.ts(2,31): error TS2307: Cannot find module '../../services/employee.service'.
src/app/staff/employees/employees/employees.component.ts(4,24): error TS2307: Cannot find module '../../types'.
src/app/staff/teams/teams/teams.component.ts(3,27): error TS2307: Cannot find module '../services/team.service'.
src/app/staff/teams/teams/teams.component.ts(4,20): error TS2307: Cannot find module '../types'.
src/app/staff/teams/team/team.component.ts(2,27): error TS2307: Cannot find module '../services/team.service'.
src/app/staff/teams/team/team.component.ts(4,20): error TS2307: Cannot find module '../types'.
src/app/production/tasks/tasks/tasks.component.ts(2,27): error TS2307: Cannot find module '../services/task.service'.
src/app/production/tasks/tasks/tasks.component.ts(4,30): error TS2307: Cannot find module '../types'.
src/app/production/tasks/task/task.component.ts(2,27): error TS2307: Cannot find module '../services/task.service'.
src/app/production/tasks/task/task.component.ts(4,20): error TS2307: Cannot find module '../types'.
src/app/production/tasks/add-task/add-task.component.ts(2,36): error TS2307: Cannot find module '../../types'.
src/app/production/tasks/add-task/add-task.component.ts(3,27): error TS2307: Cannot find module '../../services/task.service'.
src/app/production/tasks/add-task/add-task.component.ts(5,31): error TS2307: Cannot find module '../../services/employee.service'.

etc...

In addition to this IntelliJ suggests me:

TS2300: Duplicate identifier 'AppModule' in app.module.ts

and:

ng: Component 'AppComponent' is not included in a module and will not be available inside a template. Consider adding it to a NgModule declaration

or for other components similar error like:

ng: Can't resolve all parameters for TasksComponent in C:/Users/admin/Desktop/erp-mes-frontend/src/app/production/tasks/tasks/tasks.component.ts: (?, [object Object])

Could someone please assist?

1 个答案:

答案 0 :(得分:2)

When moving files around, you have to ensure that all file references are updated to account for the file's new location. Did you just move files and not update them accordingly?

Go to app.module.ts and any other file that contains imports/exports and ensure the file URL is updated with the new locations.

For example, import { Module } from './settings/module'; would have to be updated to import { Module } from './new_folder/settings/module'; or other appropriate folder structure.

If you're using an IDE, it should point out incorrect locations to you.