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

Error in setup: "Error: You must use this function within the "setup()" method, or insert the store as first argument." #71

Closed
rafaelmagalhaes opened this issue Jul 5, 2022 · 6 comments · Fixed by #72

Comments

@rafaelmagalhaes
Copy link

I started a new nuxt project form scratch added nuxt-composition-api and vuex-composition-helpers package

I get this error Error in setup: "Error: You must use this function within the "setup()" method, or insert the store as first argument." when trying to access store

// index.vue

<template>
  <div>
    {{ getLoadingState }}
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from "@nuxtjs/composition-api";
import { useNamespacedGetters } from "vuex-composition-helpers";

export default defineComponent({
  name: "Index",
  setup() {
    const { getLoadingState } = useNamespacedGetters("loading", [
      "getLoadingState",
    ]);
    const nuts = ref("text");

    return {
      nuts,
      getLoadingState,
    };
  },
});
</script>

// nuxt.config.ts

buildModules: [
    // https://go.nuxtjs.dev/typescript
    "@nuxt/typescript-build",
    "@nuxtjs/composition-api/module",
  ],

build: {
    transpile: ["vuex-composition-helpers"],
  },

/store/loading/index.js

export const state = () => ({
  loading: false,
});

export const getters = {
  getLoadingState: (state) => state.loading,
};
export const mutations = {
  setLoading(state, payload) {
    state.loading = payload;
  },
};
export const actions = {
  toggleLoading({ commit }, payload) {
    commit("setLoading", payload);
  },
};
"dependencies": {
    "@nuxtjs/axios": "^5.13.6",
    "@nuxtjs/composition-api": "^0.32.0",
    "core-js": "^3.19.3",
    "nuxt": "^2.15.8",
    "vue": "^2.6.14",
    "vue-server-renderer": "^2.6.14",
    "vue-template-compiler": "^2.6.14",
    "vuex-composition-helpers": "^1.1.0",
    "webpack": "^4.46.0"
  },
  "devDependencies": {
    "@nuxt/types": "^2.15.8",
    "@nuxt/typescript-build": "^2.1.0"
  }

@vate
Copy link

vate commented Jul 5, 2022

Happening to me similarly:

As I see from the Vue 2.7 release blog post, the new version includes some backported features that make the use of @vue/composition-api obsolete. Indeed, in said plugin there is a new warning that states that "With the release of Vue 2.7, which has Composition API built-in, you no longer need this plugin".

vuex-composition-helpers uses @vue/composition-api. . I've tried to use it with version ^2.0.0 (@next), but anyway I get this same error as @rafaelmagalhaes, probably because it is intended to work with vue 3 and not vue 2.7.

@rafaelmagalhaes
Copy link
Author

Happening to me similarly:

As I see from the Vue 2.7 release blog post, the new version includes some backported features that make the use of @vue/composition-api obsolete. Indeed, in said plugin there is a new warning that states that "With the release of Vue 2.7, which has Composition API built-in, you no longer need this plugin".

vuex-composition-helpers uses @vue/composition-api. . I've tried to use it with version ^2.0.0 (@next), but anyway I get this same error as @rafaelmagalhaes, probably because it is intended to work with vue 3 and not vue 2.7.

Thanks for this, I managed to get it working by downgrading these packages


  "vue": "2.6.14",
  "vue-template-compiler": "2.6.14",
  "vue-server-renderer": "2.6.14"

@vate
Copy link

vate commented Jul 5, 2022

Good to know! Let's hope for some changes or feedback regarding vue 2.7

@davidmeirlevy
Copy link
Contributor

Hi!

Thanks for this issue!
I thing the problem with Vue 2.7 is this breaking change:

If you were previously using @vue/composition-api, update imports from it to vue instead.

Probably will need to fix it on v1 version of the package.

LeSuisse added a commit to LeSuisse/vuex-composition-helpers that referenced this issue Jul 12, 2022
This uses `vue-demi` [0] to determine if the imports needs to be done from
`vue` or the `@vue/composition-api` plugin.

Closes greenpress#71.

[0] https://github.com/vueuse/vue-demi
@LeSuisse
Copy link
Contributor

I opened a PR to support Vue 2.7 without breaking the compat with Vue 2.6 thanks to Vue-Demi, see #72

LeSuisse added a commit to LeSuisse/vuex-composition-helpers that referenced this issue Jul 12, 2022
This uses `vue-demi` [0] to determine if the imports needs to be done from
`vue` or the `@vue/composition-api` plugin.

Closes greenpress#71.

[0] https://github.com/vueuse/vue-demi
LeSuisse added a commit to LeSuisse/vuex-composition-helpers that referenced this issue Jul 13, 2022
Vue < 2.7.0 is not supported anymore.

Closes greenpress#71.
davidmeirlevy pushed a commit that referenced this issue Jul 28, 2022
* TypeScript: 3.9.10 -> 4.7.4

Recent versions of @vue/composition-api needs a more recent version of
TypeScript than 3.9.10. Otherwise TypeScript is confused by some new
syntaxes.

ts-jest has also been upgraded to a more recent version in order to
support TypeScript 4.7.4. Since recent versions of ts-jest only support
recent version of Jest, Jest has also been upgraded.

* Add support of Vue 2.7

Vue < 2.7.0 is not supported anymore.

Closes #71.
@davidmeirlevy
Copy link
Contributor

fixed at version 1.2.0. notice that 1.1.1 supports vue up to 2.6.x

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

Successfully merging a pull request may close this issue.

4 participants