score:0

this mvce:

// main.ts
import file from './file.json';
console.log(file);

// file.json
{ "hello": "world" }

// index.d.ts
declare module '*.json' {
    const value: any;
    export default value;
}

// tsconfig.json
{
  "compileroptions": {
    "target": "es5",
    "module": "commonjs",
    "esmoduleinterop": true,
    "resolvejsonmodule": true
  }
}

can do this:

> tsc
> node main.ts
{ hello: 'world' }

perhaps you should add the json declaration file.

i'd also suggest another way: adding the webpack json-loader, and including 'json' to module.exports.resolve.extensions in webpack.config.json.

note that every json is a valid js file - if this file is not use by other entities, you can replace its extension by .js and add export default { "nodes": ... at the beginning of the file.


Related Query