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"]
},
}
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"]
},
}
Share
Improve this question
asked Sep 2, 2021 at 11:15
Shubham ShawShubham Shaw
1,0053 gold badges15 silver badges30 bronze badges
2 Answers
Reset to default 22Add 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);
example tsconfig.json
"compilerOptions": {
"baseUrl": "src",
...
"paths": {
"@config":["src/config/*"],
...
},`
import { xConfig } from '@config/index';