Bikas
Bikas

Reputation: 2759

require('file.json') doesn't work in webpack

I've a JSON file which I want to load in a Typescript class. Normally a syntax for that is

let json = require('file.json');
// Use of json file in TS class

This works perfectly fine under normal circumstances. But when I try to compile entire code with webpack, code doesn't work. I see the output code is replaced with following

var json = __webpack_require__(2);

This doesn't make much sense. Can somebody tell me what's going on under the hood and how to fix this issue?

Upvotes: 4

Views: 3636

Answers (1)

David Bradshaw
David Bradshaw

Reputation: 13087

You need to configure WebPack to load JSON files.

https://github.com/webpack/json-loader

Upvotes: 1

Related Questions