denoland / fresh

The next-gen web framework.
https://fresh.deno.dev
MIT License
12.25k stars 627 forks source link

n00b struggling with deploying fresh project with deno kv #2443

Closed crowlsyong closed 4 months ago

crowlsyong commented 4 months ago

I'm playing around with building a URL shortener (repo) via fresh framework and deno kv. I am using github actions and I can't fix the build step, here is the error:

error: Uncaught (in promise) TypeError: Deno.openKv is not a function export const kv = await Deno.openKv(); ^ at file:///home/runner/work/advrk-io/advrk-io/services/database.ts:5:30 Error: Process completed with exit code 1.

Direct link to database file in my repo

I have tried adding the --unstable and --unstable-kv to the project but no dice.

I have done some research: I have looked through the Deno KV docs and Deno Deploy docs and I couldn't seem to find a solution. I also googled my exact error and couldn't find a solution.

Obligatory "it works on my machine though" comment (because it does work locally on my machine lol).

I am a n00b, my code sucks, you will not offend me by telling me that my code is garbage. Any help is appreciated. I'm happy to bring this issue to the Deno KV github page if that is a more appropriate fit.

❤️💻

marvinhagemeister commented 4 months ago

Passing arguments AFTER deno task myscript will not pass the arguments to Deno, but to the invoked task instead. In the linked CI output this command is called:

deno task build --unstable-kv

# which gets turned to this
deno run -A dev.ts build --unstable-kv

This passes the --unstable-kv flag to the dev.ts script, but not to deno run itself. Interestingly, that's already done correctly for the start task.

You can resolve this error by updating the build task inside deno.json:

  {
    "tasks": {
      "start": "deno run -A --watch=static/,routes/ --unstable-kv dev.ts",
-     "build": "deno run -A dev.ts build"
+     "build": "deno run -A --unstable-kv dev.ts build"
     }
  }

And then you can keep calling deno task build in your CI. I'd recommend doing the same change to the preview task.