TypeScript introduced moment.js error "Could not find Module moment" and solutions

npm i momentAfter the download is complete the moment, introduced in ts file

    import * as moment from "moment";

The results mad error, moment module not found.

Ts first thought is the lack of definition files, would like to direct download npm i @types/moment, it's still not finished after the next, the official website open a search, said that moment the module already has its own type definitions file, do not download

Open node_modules / moment to look, there really is

But that is not so in ts, and began frantically Baidu.
After a pass operation, see an answer, roughly its own definition file that moment may still have a problem, still need maintenance

At this point I:

He also gives a solution, using the unified management of these statements typings file

  • npm i typingsAfter the download is complete the project appear in a folder typings
  • typings install dt~moment --global --saveDownload the moment of definition files. Once downloaded, the error resolved

Guess you like

Origin www.cnblogs.com/dairyDeng/p/12071467.html