in my typescript project, i am able to re-export my default exports in index.ts of a folder.
for eg:
export { default as BaseError } from "./errorResponse";
but i am unable to export JSON files like this.
export * as configFiles from "./config";
how to bundle and export JSON files such that i can use it in paths of tsconfig
{
"compilerOptions": {
"paths": {
"@errorClass": ["src/helpers/errorClasses"],
"@config": ["src/config"],
"@routes": ["src/routes"]
},
}
Add the following options inside your tsconfig.json file:
{
"compilerOptions": {
"esModuleInterop": true,
"resolveJsonModule": true
}
}
After updating tsconfig file export configFile like below:
export { default as configFiles } from "./config.json";
Now to import the configFiles inside your code use below:
import { configFiles } from "./file-path-to-configFiles-variable";
console.log(configFiles);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With