跳到主内容

Uncaught TypeError: Object(...) is not a function at createPinia (pinia.mjs?be92:907:1)

· 1分钟阅读

问题

pinia 作为 vue 官方认可的状态管理库,今天想要在 vue3 里集成 pinia 的时候,当启动应用的时候,发现控制台报了以下错误。

Uncaught TypeError: Object(...) is not a function
at createPinia (pinia.mjs?be92:907:1)

下面贴上代码

import { createApp } from "vue";
import App from "./App.vue";
import { createPinia } from "pinia";

createApp(App).use(createPinia()).mount("#app");

原因

主要是因为 @vue/reactivity 版本问题,在 @vue/reactivity@3.1.1 版本没有 effectScope 属性,导致 createPinia 方法报错。

解决

解决方法也很简单,只需要升级 @vue/reactivity 到 3.2.31 版本即可。

npm i @vue/reactivity@3.2.31
// or
yarn add @vue/reactivity@3.2.31