Cannot read property 'storeId' of undefined

Hi there,

I have configured the magento 2 integration with Vue Storefront and when starting the server I get this error:
Error during render : /error
TypeError: Cannot read property ‘storeId’ of undefined
at buildBaseStoreView (core/lib/multistore.ts:45:117)
at currentStoreView (core/lib/multistore.ts:59:59)
at _prepareCacheStorage (core/lib/storage-manager.ts:8:36)
at Object.init (core/lib/storage-manager.ts:31:38)
at Module…/core/modules/url/index.ts (core/modules/url/index.ts:6:43)
at webpack_require (webpack/bootstrap:25:0)
at Module…/src/modules/client.ts (src/modules/client.ts:2:0)
at webpack_require (webpack/bootstrap:25:0)
at Module…/core/modules-entry.ts (server-bundle.js:5861:76)
at webpack_require (webpack/bootstrap:25:0)

It is a multistore and the configuration for Storeviews is:
“storeViews”: {
“multistore”: true,
“commonCache”: false,
“mapStoreUrlsFor”: [
“en”,
“es”,
“nl”
],
“en”: {
“storeCode”: “default”,
“storeId”: 1,
“name”: “Default”,
“url”: “”,
“appendStoreCode”: false,
“elasticsearch”: {
“host”: “/api/catalog”,
“index”: “vue_storefront_catalog”
},
“tax”: {
“sourcePriceIncludesTax”: false,
“defaultCountry”: “ES”,
“defaultRegion”: “”,
“calculateServerSide”: true
},
“i18n”: {
“fullCountryName”: “United States”,
“fullLanguageName”: “English”,
“defaultLanguage”: “EN”,
“defaultCountry”: “US”,
“defaultLocale”: “en-US”,
“currencyCode”: “EUR”,
“currencySign”: “EUR”,
“dateFormat”: “HH:mm D-M-YYYY”
}
},
“es”: {
“storeCode”: “es”,
“storeId”: 4,
“name”: “ES”,
“url”: “/es”,
“appendStoreCode”: true,
“elasticsearch”: {
“host”: “/api/catalog”,
“index”: “vue_storefront_catalog_es”
},
“tax”: {
“sourcePriceIncludesTax”: false,
“defaultCountry”: “ES”,
“defaultRegion”: “”,
“calculateServerSide”: true
},
“i18n”: {
“fullCountryName”: “Spain”,
“fullLanguageName”: “Spanish”,
“defaultLanguage”: “ES”,
“defaultCountry”: “ES”,
“defaultLocale”: “es-ES”,
“currencyCode”: “EUR”,
“currencySign”: “EUR”,
“dateFormat”: “HH:mm D-M-YYYY”
}
},
“nl”: {
“storeCode”: “nl”,
“storeId”: 3,
“name”: “NL”,
“url”: “/nl”,
“appendStoreCode”: true,
“elasticsearch”: {
“host”: “/api/catalog”,
“index”: “vue_storefront_catalog_nl”
},
“tax”: {
“sourcePriceIncludesTax”: false,
“defaultCountry”: “NL”,
“defaultRegion”: “”,
“calculateServerSide”: true
},
“i18n”: {
“fullCountryName”: “Netherlands”,
“fullLanguageName”: “Dutch”,
“defaultCountry”: “NL”,
“defaultLanguage”: “NL”,
“defaultLocale”: “nl-NL”,
“currencyCode”: “EUR”,
“currencySign”: “EUR”,
“dateFormat”: “HH:mm D-M-YYYY”
},
I hope you can help. Thank you!

Hello.
Look at the line from error:

storeId: config.defaultStoreCode && config.defaultStoreCode !== '' ? config.storeViews[config.defaultStoreCode].storeId : 1,

It looks like you provided not existing storeCode in defaultStoreCode

I have managed to fix it, but now I get another error. I can see the VS front-end but it is not connected to Magento2 properly.

When I run npm run dev on vue-storefront I get this error:

 [module] VS Modules registration finished. { succesfulyRegistered: '0 / 0', registrationOrder: [] }
Calling asyncData in Home Page (core) null
Entity cache is enabled for productList null
Result from ES for ... (attribute),  ms=1788 null
Result from ES for ... (product),  ms=1855 null
Result from ES for ... (taxrule),  ms=53 null
Top-most asyncData executed null
Result from ES for ... (category),  ms=102 null

Elastic search settings:
“elasticsearch”: {
“host”: “localhost”,
“index”: “vue_storefront_catalog”,
“port”: 9200,
“protocol”: “http”,
“requestTimeout”: 5000,
“min_score”: 0.01,
“indices”: [
“vue_storefront_catalog”,
“vue_storefront_catalog_en”,
“vue_storefront_catalog_es”,
“vue_storefront_catalog_nl”

Elastic search version
“version” : {
“number” : “7.10.0”

In Magento 2 in the configuration of Vue Storefront I chose ES version: ElasticSearch 6+

I have checked many times the settings in Magento 2, vue-storefront, vue-storefront-api and mage2vs, the index and indices seem to be fine, I do not know what to do. Any idea?

Hello @andy1122,
at first. Please share the solution with the community. One day someone will have the same problem and will find this thread.

About the rest, you should not use mage2vs, use magento2-vsbridge-indexer - only this one supports ES7. Structure of Elasticsearch looks different for this version. So make sure to:

  1. Purge your ES
  2. Configure magento2-vsbridge-indexer
  3. Make full reindex

Thank you @Fifciuu. For the previous issue it seems that my multi-store configuration was wrong, so I recreated the storeViews in Magento and changed the local.json settings and it worked.