question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Import @apollo/client/core unnecessarily require react

See original GitHub issue

Intended outcome: Doesn’t need to have react installed when only @apollo/client/core is used. It was fine at v3.4.9.

Actual outcome: panic because I don’t have react.

How to reproduce the issue: use latest version 3.4.12 and use ApolloClient without react in package.json

Versions System: OS: macOS 11.5.2 Binaries: Node: 14.15.2 - ~/.nvm/versions/node/v14.15.2/bin/node Yarn: 1.22.5 - ~/.yarn/bin/yarn npm: 7.6.3 - /usr/local/bin/npm Browsers: Chrome: 93.0.4577.63 Edge: 93.0.961.44 Firefox: 91.1.0 Safari: 14.1.2

** clues ** in @apollo/client/utilities/utilities.cjs.js, in v3.4.12 there’s var __ = require('..'); which not exists in v3.4.9

** error stack **

internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'react'
Require stack:
- /usr/local/lib/node_modules/---/node_modules/@apollo/client/react/context/context.cjs.js
- /usr/local/lib/node_modules/---/node_modules/@apollo/client/react/react.cjs.js
- /usr/local/lib/node_modules/---/node_modules/@apollo/client/main.cjs.js
- /usr/local/lib/node_modules/---/node_modules/@apollo/client/utilities/utilities.cjs.js
- /usr/local/lib/node_modules/---/node_modules/@apollo/client/link/core/core.cjs.js
- /usr/local/lib/node_modules/---/node_modules/@apollo/client/core/core.cjs.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/---/node_modules/@apollo/client/react/context/context.cjs.js:6:13)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:11
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
benjamncommented, Sep 20, 2021

Thanks for the update @korbav!

@ianhe8x and others, please give @apollo/client@3.4.13 (which includes #8817) a try when you have a chance. 🙏

3reactions
benjamncommented, Sep 20, 2021

Sorry for the auto-close. We’ll close this after confirming the next @apollo/client version works for everyone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

You no longer need to import React from 'react'
This allows us to not import React, however, you'll need to import React to use Hooks and other exports that React provides.
Read more >
Introducing the New JSX Transform – React Blog
With the new transform, you can use JSX without importing React. Depending on your setup, its compiled output may slightly improve the bundle ......
Read more >
5 Ways to Avoid React Component Re-Renderings
In this article, I will discuss 5 methods to avoid unnecessary re-renderings in React components. 1. Memoization using useMemo() and UseCallback() Hooks.
Read more >
How to Remove Unused Dependencies in React - Pluralsight
React focuses on using external dependencies for development. These dependencies are reusable react components imported as npm packages.
Read more >
Get started with Apollo Client - Apollo GraphQL Docs
Create a new React project locally with Create React App, or ... In index.js , let's first import the symbols we need from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found