apollo: Failed to resolve import "@vue/apollo-composable"
I created an app with nuxtjs v3 rc-13 and @nuxtjs/apollo@5.0.0-alpha.3 based on a pre defined project that I created with nuxt 3 rc-11.
After I installed my dependencies and started npm run dev I got the error, thta @vue/apollo-composable module is missing. That was because I forgot to remove import statements from my old project. After I removed them and cleared the nuxi cache I restarted the app and still got the error [plugin:vite:import-analysis] Failed to resolve import "@vue/apollo-composable" from "pages/[...pages].vue". Does the file exist?
I double checked that there is no import on my side. I guess that using useQuery with the nuxt configuration apollo: { autoImports: true } doesn’t work correctly. I Checked the dependencies of the @nuxtjs/apollo@5.0.0-alpha.3 module and saw, that it uses @vue/apollo-composable internally, which is present in the modules node_module folder.
After I installed the package @vue/apollo-composable as my dependency, everything seems to work. But I think that’s the wrong way. Could you please check this behaviour?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 7
- Comments: 41
@ifusiontt The manually imported useQuery uses a different instance than the one defined in the module (the one being exposed in #imports). Therefore you would need to provide the apollo client yourself.
For example (plugins/apollo.ts):
You can also use provideApolloClients if you need to use multiple clients.
This issue is still present using node v18.13.0 and npm v9.4.0 I am with “@nuxtjs/apollo”: “^5.0.0-alpha.5” and “nuxt”: “^3.1.1”
useQuery has the issue and still it’s not solved. useAsyncQuery works fine.
Indeed when I force installed @vue/apollo-composables, I now have access to useQuery.
Having the same problem but only when i make use of
useMutation- Node 16/NPM 7 on Nuxt rc12I’m having this issue as well with
"@nuxtjs/apollo": "^5.0.0-alpha.6"and"nuxt": "^3.2.2". Actually useMutation seem completely broken. When using useMutation within<script setup>it causes nuxt to break withFailed to resolve import "@vue/apollo-composable" from "pages/applicants/[id]/[interviewId]/edit.vue". Does the file exist?error. If I install@vue/apollo-composablethis fixes the issue, which sort of seems like a hack since is should work likeuseQueryanduseAsyncQuery. As well theconst { mutate } = useMutation(MY_MUTATION)and callingmutate(varabiles)cause an errorError: Apollo client with id default not found. Use provideApolloClient() if you are outside of a component setup.. See issue 535. Any thoughts on this? Pretty frustrating at this point.https://stackblitz.com/edit/nuxt-starter-fvrzqo
This project was created with nodejs v18.12.1 and npm v8.19.2. So you will find differences inside the package-lock.json files.
I guess it has something to do with the current npm version. I am using nvm and had node v16.14.2 installed. But nvm also installs npm v8.5.0 wich also seems to cause these problems.
After downgrading to node v15.14.0 (wich uses npm v7.7.6) I can run the project. When you delete my package-lock.json and reinstall the project on StackBlitz (wich uses node v16.14.2 and npm v7.17.0) the project runs fine.
@Der-Alex i’m going to quit my computer. Can you share your project to @Diizzayy ?
I’d definitely contribute and open a PR if I had the time, but unfortunately, that’s not feasible right now. Opting to move away and install stable packages independently seems like the best choice to avoid potential headaches in the future.
With following versions - useMutation not working. few days back useAsyncQuery worked fine for mutations as well. As of now its not sending graphql call to server and we dont see any call in network tab. It became blocker for me. node - 18.18.0, npm 9.8.1 “nuxt”: “^3.6.2”,
“@vue/apollo-composable”: “^4.0.0-beta.8”,
“@nuxtjs/apollo”: “^5.0.0-alpha.6”,
I’m having the same issue as described above, getting an error that
@vue/apollo-composableis missing. Deletingnode-modulesandlock.json, and running npm install again didn’t fix it.ERROR Failed to resolve import "@vue/apollo-composable" from "components/x.vue". Does the file exist? (x2)But manually installing via
npm i -D @vue/apollo-composable@latest --legacy-peer-depsdoesn’t fix my problem either, since Apollo stops working with an error:Unexpected string literal "development". Expected ')' to end a compound expression.in filegraphql-tag.js:Please note that everything was working fine, until I touched the package.json to upgrade a seemingly unrelated package, TailwindCSS.
Any other ideas, or suggestion for a real fix?
I had to stop using this module as it doesn’t save use cached data 😞
@iamandrewluca It is a dependency that is needed by the
@vue/apollo-composableto work properly. I expect that every dependency that a third party package needs, gets installed directly, so that I can use that package without any issues. And thats the problem here.Otherwise it should be mentioned in the documentation, that other packages have to be installed to make
@vue/apollo-composablework properly.Also I think
npm i -D @vue/apollo-composable@latest --legacy-peer-depsshould be used instead of--forceToday I was fiddling around a bit with the
nuxt-modules/apollocode. I cloned it on my local machine and tried to install it withnpm installwhich didn’t work. After checking the sources I found that the package seems to get built withpnpminstead ofnpm. So I installed it withpnpm installand got this:I could install it and I could even run the playground and could mutate the todo demo!
So I thought maybe this works with a fresh nuxt install as well.
The installation still complains about missing peers. That also should be fixed! I guess this has something to do with apollo-composable trying to keep giving support for vue 2 and the vue composition api.
BUT! After that installation with pnpm
useQueryworks fine! So we definitely have different results when usingnpmandpnpm@Diizzayy I hope this helps you finding the real issue here.
same here, nothing has fixed this.
Also having the same problem using useMutation and useQuery. useAsyncQuery works fine.
If I import the composable manually like below, the error “Failed to resolve import “@vue/apollo-composable”” goes away import { useQuery } from ‘@nuxtjs/apollo/node_modules/@vue/apollo-composable’;
However it presents another error; Uncaught (in promise) Error: Apollo client with id default not found. Use provideApolloClient() if you are outside of a component setup.
@Diizzayy Not sure what’s happening… When I download the project from StackBlitz and install and run it, everything works. When I create a new project with
npx nuxi init projectname,npm i,npm i -D @nuxtjs/apollo@next,npm run devwith the same nuxt.config.ts and index.vue, I get the error…I’m going to dig deeper…
When I force add
@vue/apollo-composableto my project it work… (npm i --force @vue/apollo-composable)I was digging a bit deeper and can say that this happens when using
useQuery.useAsyncQueryworks fine.