nuxt-modules / apollo

Nuxt.js module to use Vue-Apollo. The Apollo integration for GraphQL.
https://apollo.nuxtjs.org
MIT License
929 stars 195 forks source link

Failed to resolve import "@vue/apollo-composable" from "pages/login.vue". Does the file exist? #477

Closed leonceaklin closed 1 year ago

leonceaklin commented 1 year ago

Environment

Describe the bug

The @vue/apollo-composable is not found.

Expected behaviour

Nuxt apollo installs @vue/apollo-composable correctly

Reproduction

  1. Install @nuxtjs/apollo@5.0.0-alpha.5 in a nuxtjs project
  2. Use for example useMutation inside a vue component.
  3. See the error when opening the page

Additional context

No response

Logs

ERROR  1:19:44 PM [vite] Internal server error: Failed to resolve import "@vue/apollo-composable" from "pages/login.vue". Does the file exist?
  Plugin: vite:import-analysis
  File: pages/login.vue:4:30
  2  |  import { ref } from 'vue';
  3  |  import { gql } from 'graphql-tag';
  4  |  import { useMutation } from '@vue/apollo-composable';
     |                               ^
  5  |  const _sfc_main = {
  6  |    __name: 'login',
      at formatError (/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41235:46)
      at TransformContext.error (/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41231:19)
      at normalizeUrl (/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:39540:33)
      at async TransformContext.transform (/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:39673:47)
      at async Object.transform (/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41506:30)
      at async loadAndTransform (/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:39313:29)
leonceaklin commented 1 year ago

I can install @vue/apollo-composable (only when I'm using --force) manually. But this shouldn't be necessary, or should it?

leonceaklin commented 1 year ago

Also, after installing @vue/apollo-composable manually. I get this error as soon as the mutation gets called in the component: Apollo client with id default not found. Use provideApolloClient() if you are outside of a component setup., even though I set it up like this: apollo: { clients: { default: { httpEndpoint: "/graphql" } }, },

I'm not sure if this error is a result of installing @vue/apollo-composable manually.

guendev commented 1 year ago

Follow this comment to resolve the missing default client https://github.com/nuxt-modules/apollo/issues/444#issuecomment-1354571194

leonceaklin commented 1 year ago

Thanks! It works for me now.