So I write a function like this to get test data for multiple environment:
export class DataHelper {
public static async getTestData(fileName: string): Promise<any> {
return await import(`../${fileName}`);
}
}
this will throw: Error: Cannot find module '../test-data.json'
await DataHelper.getTestData('test-data.json')
but this will work:
await DataHelper.getTestData('TestScript')
also this will work:
await import('../test-data.json')
this is my tsconfig.json
{
"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__/*"]
}
Can anyone explain what is happening and what should I do instead?