examples
examples copied to clipboard
I can't seem to get "getMiniflareBindings()" to work?
In the blog example you can use getMiniflareBindings() to get access to the global env variables. I am trying to do the same thing in my project but can't replicate the functionality.
bindings.d.ts file:
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
}
Trying to use it:
const env = getMiniflareBindings()
Error:
ReferenceError: getMiniflareBindings is not defined
build.js:
import { build } from 'esbuild'
try {
await build({
entryPoints: ['./src/index.ts'],
bundle: true,
outdir: './dist/',
sourcemap: true,
minify: true
})
} catch(err) {
process.exitCode = 1;
}
tsconfig.json:
{
"compilerOptions": {
"allowJs": true,
"target": "esnext",
"lib": ["esnext"],
"moduleResolution": "node",
"resolveJsonModule": true,
"inlineSourceMap": true,
"module": "esnext",
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strict": true,
"noImplicitAny": true,
"noEmit": true,
"types": [
"@cloudflare/workers-types",
"@types/bcryptjs"
]
},
"ts-node": {
"transpileOnly": true
},
"include": ["./src/**/*", "bindings.d.ts"]
}
Any idea what I am doing wrong?