【问题标题】:TS2307: Cannot find module (all modules) - after moving foldersTS2307:找不到模块(所有模块) - 移动文件夹后
【发布时间】:2019-02-22 22:25:28
【问题描述】:

我决定移动文件夹以便按如下方式组织模块:

自动更改app.module.ts:

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

但是,当我尝试使用 npm install 或 ng serve 时,我得到:

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'.

等等……

除了这个 IntelliJ 建议我:

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

和:

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

或对于其他组件类似的错误,如:

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])

有人可以帮忙吗?

【问题讨论】:

  • 您到底对什么感到困惑?你移动了文件。该错误表明这些文件不再存在。它们确实没有——你只是移动了它们。那个错误让你困惑的是什么?

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


【解决方案1】:

在移动文件时,您必须确保更新所有文件引用以考虑文件的新位置。您是否只是移动了文件而不是相应地更新它们?

转到 app.module.ts 和任何其他包含导入/导出的文件,并确保文件 URL 已更新为新位置。

例如,import { Module } from './settings/module'; 必须更新为 import { Module } from './new_folder/settings/module'; 或其他适当的文件夹结构。

如果您使用的是 IDE,它应该会向您指出不正确的位置。

【讨论】:

  • 感谢您的回复;)感谢您,我注意到重构后组件中的某些导入确实很奇怪...
  • 没问题。移动任何东西时,下一步应该是更新它的位置参考。此外,一个好的 IDE 可以让您为每次位置更新批量重构匹配的 URL。
  • 我确信 IntelliJ 可以处理它,但可能会出现重复的文件夹名称和重复移动的模块阻碍。或者也许,无生命物体的自然反常;)如果手动更改对我有帮助,我会给你最好的答案;)祝我好运:)
猜你喜欢
  • 2017-03-09
  • 1970-01-01
  • 2022-11-02
  • 1970-01-01
  • 2017-07-17
  • 2019-11-29
  • 2017-10-13
  • 2017-09-27
  • 1970-01-01
相关资源
最近更新 更多