【问题标题】:Getting error as Cannot find module for Entities由于找不到实体模块而出现错误
【发布时间】:2021-05-29 02:12:36
【问题描述】:

在已创建新组件和新实体中,在新组件和旧组件中导入的那些实体 在新组件中获取ng build 时出现错误:error TS2307: Cannot find module ../entities/user,未显示错误旧组件。

新组件:

import { Component, OnInit } from '@angular/core';
import {User} from '../entities/user';

@Component({
  selector: 'app-usermanagement-page',
  templateUrl: './usermanagement-page.component.html',
  styleUrls: ['./usermanagement-page.component.scss']
})
export class UserManagementComponent implements OnInit {
  user:User

  constructor() { }

  ngOnInit() {}
}

Path :src/app/usermanagement-page

实体:

export class User {
    id: number;
    username: string;
    password: string;
    firstName: string;
    lastName: string;
    role: string;
    status: string;
    lastLoginTime: number;
    accessCount: string;
    region: string
}

Entity Path :src/app/entities

【问题讨论】:

  • 能否分享一下你的实体文件的路径?
  • 请检查您的实体路径是否正确?
  • @Aman Gojariya 在旧组件中添加相同的路径并构建不显示错误,它只显示错误新创建的组件
  • 你的两个组件在同一个目录或文件夹中?
  • 不,它是不同的文件夹:src/app/device-page

标签: angular typescript angular6


【解决方案1】:

在您的新组件中尝试以下导入语句

import {User} from './entities/user';

【讨论】:

    猜你喜欢
    • 2019-06-30
    • 1970-01-01
    • 2018-05-07
    • 2018-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-25
    • 2018-01-11
    相关资源
    最近更新 更多