travis-r6s / gridsome-plugin-flexsearch

Add lightning fast search to Gridsome with FlexSearch
24 stars 7 forks source link

Getting Object.fromEntries is not a function when deploying in Netlify #48

Closed SahilMaharaj closed 4 years ago

SahilMaharaj commented 4 years ago

Hi there,

All works fine on my local but when deploying I get the following:

TypeError: Object.fromEntries is not a function at collectionStore.data.map.node (/opt/build/repo/node_modules/gridsome-plugin-flexsearch/gridsome.server.js:72:26) at Array.map () at getStoreCollection (/opt/build/repo/node_modules/gridsome-plugin-flexsearch/gridsome.server.js:56:35) at collection (/opt/build/repo/node_modules/gridsome-plugin-flexsearch/gridsome.server.js:122:14) at /opt/build/repo/node_modules/gridsome-plugin-flexsearch/node_modules/p-map/index.js:57:28

Any help would be much appreciated :)

SahilMaharaj commented 4 years ago

My gridsome.config.js

module.exports = {
  siteName: 'Gridsome',
  plugins: [
    {
      use: '@gridsome/vue-remark',
      options: {
        typeName: 'Cities', // Required
        baseDir: './cities', // Where .md files are located
        pathPrefix: '/cities', // Add route prefix. Optional
        template: './src/templates/Cities.vue', // Optional
      }
    },
    {
      use: '@gridsome/vue-remark',
      options: {
        typeName: 'Organisations', // Required
        baseDir: './organisations', // Where .md files are located
        refs: {
          locations: {
            typeName: 'Locations',
            create: true
          }
        },
        pathPrefix: '/organisations', // Add route prefix. Optional
        template: './src/templates/Organisations.vue', // Optional
      }
    },
    {
      use: 'gridsome-plugin-flexsearch',
      options: {
        searchFields: ['title', 'desc'],
        collections: [
          {
            typeName: 'Cities',
            indexName: 'Cities',
            fields: ['title', 'desc']
          },
          {
            typeName: 'Organisations',
            indexName: 'Organisations',
            fields: ['title', 'desc']
          }
        ]      
      }
    }
  ]
}
travis-r6s commented 4 years ago

This plugin requires at least Node version 12 - if you are using a version below that, then Object.fromEntries will be undefined.

Could you try upgrading Node, and see if that works?

travis-r6s commented 4 years ago

Sorry, just saw you said it was showing that on deploy - you will need to set the node version in the build environment, for example adding a NODE_VERSION env on Netlify.

SahilMaharaj commented 4 years ago

That did the trick, thanks mate!