My current setup involves using cloudflare workers with miniflare. I have structured a bindings.d.ts
file as follows:
export interface Bindings {
ENV: string
MYSQL_URL: string
JWT_SECRET: string
JWT_ACCESS_EXPIRATION_MINUTES: number
JWT_REFRESH_EXPIRATION_DAYS: number
JWT_RESET_PASSWORD_EXPIRATION_MINUTES: number
JWT_VERIFY_EMAIL_EXPIRATION_MINUTES: number
}
declare global {
function getMiniflareBindings(): Bindings
}
The file includes a global declaration of the function getMiniflareBindings()
. In another part of my project, I call this function using:
getMiniflareBindings()
However, when running my code, an error pops up saying:
ReferenceError: getMiniflareBindings is not defined
Within my build.js file, I import and utilize 'esbuild' like so:
import { build } from 'esbuild'
try {
await build({
entryPoints: ['./src/index.ts'],
bundle: true,
outdir: './dist/',
sourcemap: true,
minify: true
})
} catch(err) {
process.exitCode = 1;
}
In my tsconfig.json file, I have specified various compiler options and included relevant types:
{
"compilerOptions": {
"allowJs": true,
...
},
...
}
I recently made an update to .bindings.d.ts by altering the declarations to include additional fields:
export interface Bindings {
ENV: string
...
DATABASE_HOST: string
}
declare global {
const ENV: string
...
const DATABASE_HOST: string
}
In my actual codebase, these values are accessed directly and utilized effectively in production and development environments. However, when it comes to testing, none of these variables seem to be properly "defined" causing issues that I am currently facing.