Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't seem to get "getMiniflareBindings()" to work? #31

Open
tokenhousetopdev opened this issue Nov 2, 2022 · 0 comments
Open

I can't seem to get "getMiniflareBindings()" to work? #31

tokenhousetopdev opened this issue Nov 2, 2022 · 0 comments

Comments

@tokenhousetopdev
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant