How to import *.json
?
As already answered you need Typescript >= 2.9 and the following settings in tsconfig.json:
{
"resolveJsonModule": true,
"esModuleInterop": true,
"module": "commonjs"
}
But there are restrictions:
You must compile to CommonJS
All your imported JSONs must reside under the rootDir
Unfortunately the "rootDir" is very often a folder beneath package.json like './src' and things would fail.
So: How to import package.json ? You can require it: const pjson = require('../package.json');