I have to import a typescript file from the Firebase storage bucket. It contains data as well as type definitions.
export interface MyData {
// ...
}
export const myData = {
// ...
}
Here is the code I came with:
export const readData = async (fileDir: string, fileName: string): Promise<object> => {
// Open the bucket
const bucket: Bucket = admin.storage().bucket()
// Define the file path in the bucket
const filePath: string = path.join(fileDir, fileName)
// Define the local file path on the cloud function's server
const tempFilePath: string = path.join(os.tmpdir(), fileName)
// Download the file from the bucket
try {
await bucket.file(filePath).download({ destination: tempFilePath })
} catch (error) {
functions.logger.error(error, { structuredData: true })
}
// Extract the needed variable export from the file
const data = require(tempFilePath)
// provide the variable
return data
}
eslint complain about:
Require statement not part of import statement.eslint@typescript-eslint/no-var-requires
On:
const data = require(tempFilePath)
What would be the right way to import the file?
Thanks