Closed 4F2E4A2E closed 1 year ago
Start a new pull request in StackBlitz Codeflow.
useStorage
only works within the nitro part of your app (within ~/server
directory), not within the vue part of your app.
Although it might be an interesting future feature for Nuxt to have isomorphic use of storage on the client side.
Thank you for clarifying, but could you provide a working example even with the server? I am not aware of any example where anywhere using nuxt, I would set a kv and see it in the devtools without any other additional setup or dependency.
I did move the code to the server, but the result is the same:
//app.vue
<template>
<div>nuxt devtools is awesome: {{ helloWorld }}</div>
</template>
<script setup lang="ts">
import { testStore } from './server/store';
const helloWorld = await testStore();
console.log(helloWorld);
</script>
//server/store.ts
export async function testStore() {
const key = 'xyz:xyz';
const storage = useStorage();
await storage.setItem(key, 'xyzValue');
const result = await storage.getItem(key);
console.log(result);
return result;
}
https://stackblitz.com/edit/github-jt6ucm-wbzxxw?file=app.vue
Environment
~/projects/github-jt6ucm ❯ npx nuxi info [22:25:02] Working directory: /home/projects/github-jt6ucm [22:25:02] Nuxt project info:
Build Modules: -
Reproduction
Describe the bug
I am not able to get the builtin nitro store to work. The error I am getting is always the same, useStorage is not defined:
I came the across the these articles [1, 2, 3] stating that there is this new functionality and kv-store (fs-lite) out of the box for nuxt, but I am just not getting it to work.
I went ahead to latest release [4] and created a project from scratch [5], like this:
1: https://nuxt.com/blog/v3-7#%EF%B8%8F-nitro-26 2: https://unjs.io/blog/2023-08-25-nitro-2.6 3: https://masteringnuxt.com/blog/24-time-saving-tips-for-nuxt3 4: https://nuxt.new/?utm_source=nuxt-com&utm_medium=dropdown&utm_campaign=home 5: https://stackblitz.com/edit/github-jt6ucm?file=app.vue
Additional context
This [1] one similar thing I could find - thx to the @create-issue documentation in-here - , but it is about unit testing the app.
1: https://github.com/nuxt/nuxt/discussions/16021
Logs