Typescript import returns “Cannot find module”

后端 未结 3 422
离开以前
离开以前 2021-01-27 09:02

I\'m trying to import a module as import Something from \"@module\", but it returns

Cannot find module \'@config\'

\"@m

3条回答
  •  渐次进展
    2021-01-27 09:55

    Note that the import will seem fine while developing by importing moment this way, but you may get an AOT error when doing a prod compile, something like, "can not use reference" or some such like that. To not elaborate over much, this has to do (as I understand it) with some CommonJS modules. Moment is very popular, so it seems to come up quite a bit.

    To get around that one (which I ran into a couple of weeks ago), set "moment" to a const:

    import * as moment from 'moment':
    
    (later where you declare consts)
    
    const _moment = moment;
    

    And then you use _moment in your code.

提交回复
热议问题