question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nuxt3 bulid error

See original GitHub issue
// shell
$ node .output/server/index.mjs
Listening on http://localhost:3000/
TypeError: extender is not a function
    at file:///Volumes/www/vue/.output/server/node_modules/pinia/dist/pinia.mjs:1558:43
    at EffectScope.run (/Volumes/www/vue/.output/server/node_modules/@vue/reactivity/dist/reactivity.cjs.js:27:24)
    at file:///Volumes/www/vue/.output/server/node_modules/pinia/dist/pinia.mjs:1558:33
    at Array.forEach (<anonymous>)
    at createSetupStore (file:///Volumes/www/vue/.output/server/node_modules/pinia/dist/pinia.mjs:1545:14)
    at createOptionsStore (file:///Volumes/www/vue/.output/server/node_modules/pinia/dist/pinia.mjs:1142:13)
    at useStore (file:///Volumes/www/vue/.output/server/node_modules/pinia/dist/pinia.mjs:1622:17)
    at setup (file:///Volumes/www/vue/.output/server/chunks/app/server.mjs:10416:23)
    at _sfc_main.setup (file:///Volumes/www/vue/.output/server/chunks/app/server.mjs:10656:23)
    at callWithErrorHandling (file:///Volumes/www/vue/.output/server/chunks/index.mjs:1957:22)
[Vue warn]: Component  is missing template or render function.

and in Browser: image

Hydration completed but contains mismatches. 

My environment:

package.json
{
  "private": true,
  "scripts": {
    "dev": "nuxi dev",
    "build": "nuxi build",
    "deploy": "yarn build && yarn start",
    "start": "node .output/server/index.mjs"
  },
  "devDependencies": {
    "naive-ui": "^2.26.0",
    "nuxt-windicss": "^2.2.8",
    "nuxt3": "latest",
    "unplugin-vue-components": "^0.17.21"
  },
  "dependencies": {
    "@pinia/nuxt": "^0.1.8",
    "pinia": "^2.0.11",
    "pinia-plugin-persistedstate": "^1.3.0"
  }
}
nuxt.config.ts
import { defineNuxtConfig } from 'nuxt3'
import Components from 'unplugin-vue-components/vite';
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';

// https://v3.nuxtjs.org/docs/directory-structure/nuxt.config
export default defineNuxtConfig({
    build: {
        // fix dev error: Cannot find module 'vueuc'
        transpile: ['vueuc'],
    },
    vite: {
        plugins: [
            Components({
                // Automatically register all components in the `components` directory
                resolvers: [NaiveUiResolver()],
            }),
        ],
        // @ts-expect-error: Missing ssr key
        ssr: {
            noExternal: ['moment', 'naive-ui'],
        },
    },
    buildModules: [
        /**
         * @see https://cn.windicss.org
         */
        'nuxt-windicss',
        /**
         * @see https://pinia.vuejs.org
         */
        '@pinia/nuxt',
    ],
    windicss: {
        analyze: true
    }
})

plugins/pinia-persist.ts
import PiniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import { defineNuxtPlugin } from '#app'

export default defineNuxtPlugin(nuxtApp => {
    nuxtApp.$pinia.use(PiniaPluginPersistedstate)
})
composables/useUser.ts
import { defineStore } from "pinia";

export default defineStore({
    id: 'user',
    state: () => ({
        a: 1
    }),
    getters: {

    },
    actions: {
    },
    persist: {
        storage: {
            getItem: (key) => { return useCookie(key, { encode: x => x, decode: x => x }).value },
            setItem: (key, value) => { useCookie(key, { encode: x => x, decode: x => x }).value = value },
        },
    },
})

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
prazdevscommented, Mar 6, 2022

Ok, with the latest createPersistedState factory function introduced in v1.4.0, I managed to have everything fully functional with useCookie even on server side.

plugins/persistedstate.ts
import { createPersistedState } from 'pinia-plugin-persistedstate'

import { defineNuxtPlugin, useCookie } from '#app'

export default defineNuxtPlugin(nuxtApp => {
  nuxtApp.$pinia.use(createPersistedState({
    storage: {
      getItem: key => {
        return useCookie(key, { encode: (x: any) => x, decode: (x: any) => x })
          .value
      },
      setItem: (key, value) => {
        useCookie(key, { encode: (x: any) => x, decode: (x: any) => x }).value =
          value
      },
    },
  }))
})
stores/user.ts
import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    username: 'PraZ',
  }),
  persist: true
})

@waset tell me if that fixes it for you as well, and I will update the Nuxt usage docs anyways. I may work later on a createNuxtPersistedState helper anyway to make things more simple.

1reaction
wasetcommented, Mar 4, 2022

If I rename the plugins to .client.ts, let it run on the client, there will be no such error, and everything will become normal again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Nuxt 3 RC-1] Error on build · Issue #1428 - GitHub
During build, I got an error related to nuxt-i18n . Feel free to close if this is because the repository is still WIP....
Read more >
Error handling · Get Started with Nuxt
Learn how to catch errors in different lifecycle. Handling Errors. Nuxt 3 is a full-stack framework, which means there are several sources of...
Read more >
Nuxt3 nuxi build ERROR [commonjs--resolver] - Stack Overflow
When i run nuxi dev everything is Ok, but nuxi build occurred this error. > @ build E:\everyday-action\webprint > nuxi build Nuxi 3.0.0...
Read more >
Deploying a new nuxt 3 app result to error - Support
Hello, I've created a new nuxt 3 app and tried to delopy it to netlify with github: stoic-fermat-995d10 The build stop when It...
Read more >
Commands and Deployment - Nuxt
nuxt dev - Launch the development server. nuxt build - Build and optimize ... a page error is encountered and let the CI/CD...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found