Uncaught ReferenceError: Cannot access 'store' before initialization
See original GitHub issueI’m trying to get this working with an existing Vue 2 app but I’m getting the error:
Uncaught ReferenceError: Cannot access ‘store’ before initialization
I have a folder within:
src
store
index.js
store.js
main.js
main.js imports the store as such:
import store from './store/index.js';
and initialises the Vue instance like so:
export const app = new Vue({
render: (h) => h(App),
store,
router,
i18n,
}).$mount('#app');
index.js in the store folder looks like:
import Vue from 'vue';
import Vuex from 'vuex';
import { state, mutations, actions, getters } from './store.js';
import createPersistedState from 'vuex-persistedstate';
Vue.use(Vuex);
export default new Vuex.Store({
state,
mutations,
actions,
getters,
plugins: [
createPersistedState({
storage: window.sessionStorage,
}),
],
});
Am I doing something wrong?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Cannot access 'store' before initialization in redux · Issue #167 ...
I'd suggest moving the configureStore() call into a separate store.js file instead, to break the dependency issue. 29
Read more >ReferenceError: Cannot access 'Store' before initialization ...
Problem was solved by moving Store class to isolated file, before it was in the same file as the global store.
Read more >ReferenceError: Cannot access before initialization in JS
The "Cannot access before initialization" error occurs when a variable declared using let or const is accessed before it was initialized in the...
Read more >ReferenceError: can't access lexical declaration 'X' before ...
A lexical variable was accessed before it was initialized. This happens within any block statement, when variables declared with let or const ...
Read more >cannot access 'store' before initialization - You.com | The AI ...
Problem was solved by moving Store class to isolated file, before it was in the same file as the global store. Open side...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

It turns out this was due to a circular dependency. The store was importing the Vue app to reference i18n
Yes, vite server started, it is an error in the browser console and the web application doesn’t render