#Hey everyone! I ran into an issue while trying to ...

11 messages · Page 1 of 1 (latest)

flint hatchBOT
#

Hey everyone! I ran into an issue while trying to access a Google API in a collection hook. The problem is that the auth library which is used by the api client is Node only, i.e. can't be used in the browser. However the bundler will include it when building the admin panel and fails. Is there a way exclude this dependency from the admin panel and include it only for building the server?

Original message from @quiet siren - Moved from #general message (in #general)

sage anchor
#

@quiet siren Yeah you can alias it within the webpack config

quiet siren
#

@sage anchor I'm using Vite tho...

sage anchor
quiet siren
#

Thanks, I'm checking this out.

quiet siren
#

@sage anchor I aliased the hook I'm importing in my collection config (which references the googleapis package) but it's still included in the admin bundle. I followed the instructions from the docs you linked, supplying a mock file that exports an empty object.

#

The import in my collection config is:

import populateFromGooglePeople from './hooks/populateFromGooglePeople'

I took the code from the vite example and added it to the admin vite config. Relevant line here:

      aliasArray.push({
        find: './hooks/populateFromGooglePeople',
        replacement: path.resolve(__dirname, './mock.js'),
      })
#

Although I believe that the code for Vite on this page is wrong anyway, since it doesn't do the same aliasing as the Webpack example.