找不到模块:错误:无法解析“ ./components/random-email-service”

时间:2019-12-13 12:52:53

标签: typescript webpack

这是我的服务等级:

let md5 = require('md5');

export default class RandomEmails {

    randomEmails = [];

    constructor(){
        this.generateRandomEmails();
    }

    generateRandomEmails():void {

        const chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
        for(let i=0;i<=60;i++){
            console.log('i'+i);
        }
    }
}

从我的index.ts像这样调用:

import "./index-style.css";
import  RandomEmails from './components/random-email-service';

export class Hero {
    id: number;
    name: string;

    constructor(name:string) {
        this.name = name;
        new RandomEmails(); //calling here;
    }

    myName()
    {
        return this.name;
    }
  }

let hero = new Hero('Arif-00');
console.log(hero.myName());

得到一个错误:

ERROR in ./src/index.ts
Module not found: Error: Can't resolve './components/random-email-service' in 'F:\JS-APP\src'
 @ ./src/index.ts 4:31-75

问题是什么?如何导入类并调用它?有人帮我吗? Unitl类未调用,可以正常工作

0 个答案:

没有答案