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

TS Error 4023 - Exported variable 'useMainStore' has or is using name 'StoreWithState' #315

Closed
kingkong404 opened this issue Dec 16, 2020 · 4 comments
Labels
need repro This issue couldn't be reproduced

Comments

@kingkong404
Copy link

kingkong404 commented Dec 16, 2020

Reproduction

Error: Exported variable 'useMainStore' has or is using name 'StoreWithState' from external module "/Users/steven/Documents/New Documents Dec 2020/boilerplate/versiontwo/node_modules/pinia/dist/pinia" but cannot be named.ts(4023)

image

Steps to reproduce the behavior

Installed pinia@next and added it to main.ts and created a new file with the example code.

main.ts

import { createApp } from "vue";
import "./assets/main.css";
import App from "./App.vue";
import { routes } from "./routes";
import { createRouter, createWebHistory } from "vue-router";
import { store } from "./store";
import { createPinia } from "pinia";

const app = createApp(App);
app.use(createPinia());
app.use(store);

export const router = createRouter({
  history: createWebHistory(),
  routes,
});

app.use(router);
app.mount("#app");

piniaStore.ts

import { defineStore } from "pinia";

export const useMainStore = defineStore({
  // name of the store
  // it is used in devtools and allows restoring state
  id: "main",
  // a function that returns a fresh state
  state: () => ({
    counter: 0,
    name: "Eduardo",
  }),
  // optional getters
  getters: {
    doubleCount() {
      return this.counter * 2;
    },
    // use getters in other getters
    doubleCountPlusOne() {
      return this.doubleCount * 2;
    },
  },
  // optional actions
  actions: {
    reset() {
      // `this` is the store instance
      this.counter = 0;
    },
  },
});
@posva posva added the need repro This issue couldn't be reproduced label Dec 17, 2020
@posva
Copy link
Member

posva commented Dec 17, 2020

Provide a minimal editable reproduction, thanks

@kingkong404
Copy link
Author

kingkong404 commented Dec 17, 2020

Hey @posva I copied the code provided in the read me to an existing project. I've added my relevant code / the two files I changed to my first comment. Although in order to provide a full repo I'd have to provide my entire project.

I am also using Vuex and was planning to transition over to Pinia. (not sure if that matters)

Any advice to what I could try or what the error means would be great! Very excited to get this working.

@kingkong404
Copy link
Author

kingkong404 commented Dec 17, 2020

@posva I think I know why its happening

Exported variable 'useMainStore' has or is using name 'StoreWithState' from external module ".../versiontwo/node_modules/pinia/dist/pinia" but cannot be named.

My file structure is set up as
Main folder <-- I's looking for Pinia here in the main (/versiontwo/node_modules/)

  • Packages
    -- Frontend
    --- node_modules <-- Pinia is installed here (/versiontwo/packages/frontend/node_modules/)

image

Note: I have VSCode set to hide Node modules folders but each package folders has it's own node modules.

@kingkong404
Copy link
Author

Actually it seems all my modules are coming from the main folder even Vue. So there goes that theory :/

image

@posva posva closed this as completed in dc56fba Dec 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need repro This issue couldn't be reproduced
Projects
None yet
Development

No branches or pull requests

2 participants