Import JSON file in node application with TypeScript

前端 未结 3 861
故里飘歌
故里飘歌 2021-01-18 10:33

I\'m really getting crazy because I can\'t find a solution for this. What I want to archive is to import a JSON file with a configuration into my TypeScript file. I\'ve lear

3条回答
  •  被撕碎了的回忆
    2021-01-18 11:00

    Examples on the web that use declare module "*.json" work because Webpack is configured to load JSON files.

    If you don't want to bother with that you can use var instead of import:

    var json = require('../config.json');

    as suggested in this answer

提交回复
热议问题