When creating a function to retrieve test data for multiple environments, I encountered an issue:
export class DataHelper {
public static async getTestData(fileName: string): Promise<any> {
return await import(`../${fileName}`);
}
}
Running this code resulted in the following error: Error: Cannot find module '../test-data.json'
await DataHelper.getTestData('test-data.json')
However, the following calls were successful:
await DataHelper.getTestData('TestScript')
And also:
await import('../test-data.json')
This is the content of my tsconfig.json file:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": true,
"sourceMap": true,
"outDir": "./lib",
"moduleResolution": "node",
"baseUrl": ".",
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"resolveJsonModule": true
},
"include": ["src", "example/**/*"],
"exclude": ["node_modules", "**/__tests__/*"]
}
I am seeking clarification on what is causing this issue and what corrective actions should be taken. Any insights would be greatly appreciated.