Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'useRef' is not exported from 'react' #186

Closed
jurredejongh opened this issue Feb 1, 2024 · 5 comments · Fixed by apollographql/apollo-client#11552
Closed

'useRef' is not exported from 'react' #186

jurredejongh opened this issue Feb 1, 2024 · 5 comments · Fixed by apollographql/apollo-client#11552

Comments

@jurredejongh
Copy link

jurredejongh commented Feb 1, 2024

Hi!

Since we updated @apollo/client to 3.9.1 and @apollo/experimental-nextjs-app-support to 0.7.1 we get the following error in Next.js when either building or using dev:

> next build

   ▲ Next.js 14.0.4
   - Environments: .env.local

Failed to compile.

./node_modules/@apollo/client/react/hooks/internal/useLazyRef.js
Attempted import error: 'useRef' is not exported from 'react' (imported as 'React').

Import trace for requested module:
./node_modules/@apollo/client/react/hooks/internal/useLazyRef.js
./node_modules/@apollo/client/react/hooks/internal/index.js
./node_modules/@apollo/client/react/hooks/useFragment.js
./node_modules/@apollo/client/react/hooks/index.js
./node_modules/@apollo/client/react/index.js
./node_modules/@apollo/client/index.js
./src/apollo.ts
./src/app/..../actions.ts
./src/app/..../layout.tsx
./node_modules/next/dist/build/webpack/loaders/next-app-loader.js?name=..../page.tsx?__next_edge_ssr_entry__


> Build failed because of webpack errors
   Creating an optimized production build  .

The apollo.ts file only contains this:

import { registerApolloClient } from '@apollo/experimental-nextjs-app-support/rsc'

export const { getClient } = registerApolloClient(() => {
  const authLink = setContext(async (_, { headers, token }) => {
    return {
      headers: {
        ...headers,
        ...(token ? { authorization: `Bearer ${token}` } : {}),
      },
    }
  })

  const httpLink = new HttpLink({
    uri: process.env.ROUTER_URL ?? 'http://127.0.0.1:4000',
    credentials: 'same-origin',
  })

  return new ApolloClient({
    cache: new InMemoryCache(),
    link: ApolloLink.from([authLink, httpLink]),
  })
})

It looks like the useRef is called in RSC since the latest version. I don't know if this is the correct repo for this error or that I need to be over at @apollo/client.

Anyone knows what is happening different?

--

There are no issues when using @apollo/[email protected] and @apollo/[email protected].

@jerelmiller
Copy link
Member

Hey @jurredejongh 👋

Thanks for the report! Apologies for the error! We had released a change in 3.8.9 that didn't get switched over to the proper import when we pulled it into our 3.9 release. I've opened apollographql/apollo-client#11552 which should fix this issue. Can you try the snapshot release to double check this fixes your issue?

npm i @apollo/[email protected]

Copy link
Contributor

github-actions bot commented Feb 1, 2024

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

@phryneas
Copy link
Member

phryneas commented Feb 1, 2024

This will be released in a few minutes as @apollo/client 3.9.2 - if that doesn't fix the problem, please feel free to reopen this issue :)

@phoebejaffe
Copy link

phoebejaffe commented Feb 1, 2024

@phryneas I'm seeing a maybe related error (using 3.9.2 as well as earlier versions ... this log is using 3.9.2):

 ⨯ ../node_modules/@apollo/client/react/context/ApolloConsumer.js
Attempted import error: 'createElement' is not exported from 'rehackt' (imported as 'React').

Any chance this is a similar issue with an import needing to be updated somewhere?

@phryneas
Copy link
Member

phryneas commented Feb 1, 2024

@benjaffe that's likely a different problem. Could you please open a new issue with a reproduction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants