Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@apollo_client.js?v=dbeae2a1:78 Uncaught Error: Could not resolve "react" imported by "rehackt". Is it installed?

While using apollo client in vite, I get the error @apollo_client.js?v=dbeae2a1:78 Uncaught Error: Could not resolve "react" imported by "rehackt". Is it installed? in the console even though I want the library without react (vanilla javascript)? I imported ApolloClient from @apollo/client/core My main.js:

//src/main.js
import { createApp } from 'vue';
import App from './App.vue';
import { ApolloClient, gql, createHttpLink, InMemoryCache } from '@apollo/client/core';
import { DefaultApolloClient } from '@vue/apollo-composable';
import { createRouter, createWebHashHistory } from 'vue-router';
import Post from '@/components/Post.vue';
import Author from '@/components/Author.vue';
import PostsByTag from '@/components/PostsByTag.vue';
import AllPosts from '@/components/AllPosts.vue';

const httpLink = createHttpLink({
    uri: 'https://localhost:8000/graphql',
});

const apolloClient = new ApolloClient({
    link: httpLink,
    cache: new InMemoryCache(),
});
const routes = [
  { path: '/author/:username', component: Author },
  { path: '/post/:slug', component: Post },
  { path: '/tag/:tag', component: PostsByTag },
  { path: '/', component: AllPosts },
];
const router = createRouter({
    history: createWebHashHistory(),
    routes: routes,
});

const app = createApp(App);

app.provide(DefaultApolloClient, apolloClient);

app.mount('#app');
like image 903
Kaleab Woldemariam Avatar asked Nov 01 '25 14:11

Kaleab Woldemariam


2 Answers

Instead of importing from: @apollo/client use: @apollo/client/core

like image 159
Yuri Lima Avatar answered Nov 03 '25 05:11

Yuri Lima


According to this article, many dependencies can be imported from @apollo/client:

-import ApolloClient from 'apollo-client'
-import { ApolloLink, concat } from 'apollo-link'
-import { HttpLink } from 'apollo-link-http'
-import { split } from 'apollo-link'
-import { onError } from 'apollo-link-error'
-import { InMemoryCache, defaultDataIdFromObject } from 'apollo-cache-inmemory'
+import { ApolloClient } from '@apollo/client/core'
+import { ApolloLink, HttpLink, split, concat } from '@apollo/client/core'
+import { onError } from '@apollo/client/link/error'
+import { InMemoryCache, defaultDataIdFromObject } from '@apollo/client/cache'
-import gql from "graphql-tag"
+import { gql } from "@apollo/client/core"
like image 41
wfsovereign Avatar answered Nov 03 '25 03:11

wfsovereign



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!