无法编译TypeScript:找不到模块“ fs”

时间:2019-05-25 11:41:18

标签: typescript mocha

我收到错误

  

TSError:⨯无法编译TypeScript:   server / src / test / test.ts(2,45):错误TS2307:找不到模块“ fs”

我运行此测试时

import "mocha"
import { writeFileSync, readFileSync } from 'fs';
import migrator from '../utils/Migrator';
import {expect} from "chai"

describe("cleanTimestamp",()=>{
    it("should round to nearest seconds",()=>{
        // migrator.start()
       const ans =  migrator.cleanTimestamp(('(1558312599408)'))
      expect(ans).equal(1558298199000);
    });
})

1 个答案:

答案 0 :(得分:0)

我使用了webstorm。我的项目根目录没有node_modules文件夹。我的node_modules跟踪对象实际上位于子目录server/中。因此,当我单击运行测试时,webstorm在根目录中搜索node_modules。为了解决这个问题,我将根目录更改为server/

enter image description here