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

TypeError: container.value is null in Nuxt3 #233

Open
zupaazhai opened this issue Feb 16, 2024 · 5 comments
Open

TypeError: container.value is null in Nuxt3 #233

zupaazhai opened this issue Feb 16, 2024 · 5 comments

Comments

@zupaazhai
Copy link

I have installed Konva and Vue Konva in my project.

I used
Konva version 8.4.3
vue-konva version 3.0.2

then when use in page,

<template>
  <v-stage :config="{ width: 200, height: 200 }">
    <v-layer>
      <v-circle :config="{ x: 100, y: 100, radius: 70, fill: "red", stroke: "black", strokeWidth: 4 }"></v-circle>
    </v-layer>
  </v-stage>
</template>

and run in Firefox
I got error

Uncaught (in promise) TypeError: container.value is null

this is how I setup in my project

  1. create plugin vue-konva.js
import VueKonva from 'vue-konva'

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(VueKonva);
})
  1. in nuxt.config.ts
plugins: [
        ...
        { src: '~/plugins/vue-konva', mode: 'client' },
]

anyone can suggest me?

@efren-corillo
Copy link

having the same issue. Did you find a solution @zupaazhai ?

 Uncaught (in promise) TypeError: container.value is null
    setup vue-konva.js:377
    node_modules vue-konva.js:28421
    callWithErrorHandling runtime-core.cjs.js:192
    callWithAsyncErrorHandling runtime-core.cjs.js:199
    node_modules vue-konva.js:28403
    flushPostFlushCbs runtime-core.esm-bundler.js:367
    flushJobs runtime-core.esm-bundler.js:405
    promise callback*queueFlush runtime-core.esm-bundler.js:308
    queueJob runtime-core.esm-bundler.js:302
    effect runtime-core.esm-bundler.js:6136
    resetScheduling reactivity.esm-bundler.js:264
    triggerEffects reactivity.esm-bundler.js:308
    triggerRefValue reactivity.esm-bundler.js:1070
    set value reactivity.esm-bundler.js:1115
    updateStageSize index.vue:134
    setup index.vue:281

@wizbit
Copy link

wizbit commented Feb 21, 2024

I managed it by putting the stage in <client-only> tags

e.g.

<template>
  <client-only>
    <v-stage :config="{ width: 200, height: 200 }">
      <v-layer>
        <v-circle :config="{ x: 100, y: 100, radius: 70, fill: "red", stroke: "black", strokeWidth: 4 }"></v-circle>
      </v-layer>
    </v-stage>
  </client-only>
</template>

@kkparkclouflake
Copy link

I'm using Quasar Framework with vue-konva, and occur same error.
I made an build file from latest commit, and change main source file from 'vue-konva.umd.js' into 'vue-konva.mjs' and it works.

You can try it; ( https://github.com/kkparkclouflake/vue-konva/tree/nightly )
yarn add https://github.com/kkparkclouflake/vue-konva#nightly
or npm i --save git+https://github.com/kkparkclouflake/vue-konva#nightly

@joeelia
Copy link

joeelia commented Apr 30, 2024

  1. Delete node_modules folder
  2. yarn add -D @rollup/plugin-commonjs
  3. Add this config to nuxt.config.js
import commonjs from '@rollup/plugin-commonjs';
export default defineNuxtConfig({
  ...,
  vite: {
    plugins: [
      commonjs() // Adding the CommonJS plugin to Vite's configuration
    ]
  },
  plugins: [
    { src: '~/plugins/vue-konva.js', mode: 'client' },
  ]
})
  1. Use this code in a new plugin file called vue-konva.js
import VueKonva from 'vue-konva';

let konvaModule;

const loadKonva = async () => {
    if (!konvaModule) {
        konvaModule = await import('konva');
    }
    return konvaModule;
};

export default defineNuxtPlugin(nuxtApp => {
    konvaModule = loadKonva();
    nuxtApp.vueApp.use(VueKonva, { Konva: konvaModule });
});
  1. run yarn again
  2. test app
  3. React with emoji if this worked for you

@boriswinner
Copy link

I'm using Quasar Framework with vue-konva, and occur same error. I made an build file from latest commit, and change main source file from 'vue-konva.umd.js' into 'vue-konva.mjs' and it works.

You can try it; ( https://github.com/kkparkclouflake/vue-konva/tree/nightly ) yarn add https://github.com/kkparkclouflake/vue-konva#nightly or npm i --save git+https://github.com/kkparkclouflake/vue-konva#nightly

Thank you so much! Your fix helped me.
I tried to use Quasar + Vue 3 + Vue Konva and got the same error.
I hope this issue gets resolved in the hew release.

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

6 participants