Typescript : require statement not part of an import statement

后端 未结 4 2357
我寻月下人不归
我寻月下人不归 2021-02-18 13:10

Typescript version 2.2.2

I wrote this require in my UserRoutzr.ts

const users =  require(path.join(process.cwd() + \"/data\"));

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-18 13:50

    may be you need dynamic module loading, and the code like this:

    import {IUser} from './lib/user';
    const users:IUser[] = require(path.join(process.cwd() + "/data"));
    

提交回复
热议问题