Skip to content

After build, it occur: Cannot read property 'state' of undefined #156

Closed
@leon-kfd

Description

@leon-kfd

My apps has used vuex, and it can run in the development environment.
But when i run vite build, it happen this error on browser:

index.js:9 Uncaught TypeError: Cannot read property 'state' of undefined
    at index.js:9
    at n (index.js:1)
    at Object.get value [as value] (index.js:1)
    at Object.get (index.js:1)
    at Object.get (index.js:1)
    at index.js:9
    at Vn (index.js:1)
    at Proxy.<anonymous> (index.js:9)
    at Proxy.<anonymous> (index.js:1)
    at nt (index.js:1)
(anonymous) @ index.js:9
n @ index.js:1
get value @ index.js:1
(anonymous) @ index.js:1
get @ index.js:1
(anonymous) @ index.js:9
Vn @ index.js:1
(anonymous) @ index.js:9
(anonymous) @ index.js:1
nt @ index.js:1
(anonymous) @ index.js:1
n @ index.js:1
G @ index.js:1
$ @ index.js:1
V @ index.js:1
j @ index.js:1
S @ index.js:1
P @ index.js:1
T @ index.js:1
C @ index.js:1
S @ index.js:1
P @ index.js:1
T @ index.js:1
C @ index.js:1
S @ index.js:1
P @ index.js:1
T @ index.js:1
C @ index.js:1
Show 28 more frames

This seems to be because vuex can't pack?
This is my code which use vuex $store.

<script lang="ts">
import { ref, computed, getCurrentInstance } from 'vue'
import Card from './Card.vue'
export default {
  name: 'Main',
  components: {
    Card
  },
  setup(props) {
    const instance: any = getCurrentInstance()
    const ctx = instance.ctx
    const selectedDate = computed(() => ctx.$store.state.selectedDate)
    return {
      selectedDate
    }
  }
}
</script>

And I don't know if I wrote it wrong.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions