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

[3.0-beta] Uncaught ReferenceError: require is not defined #6035

Closed
ashubham opened this issue Mar 9, 2020 · 2 comments · Fixed by #6361
Closed

[3.0-beta] Uncaught ReferenceError: require is not defined #6035

ashubham opened this issue Mar 9, 2020 · 2 comments · Fixed by #6361

Comments

@ashubham
Copy link

ashubham commented Mar 9, 2020

Trying to use apollo-client with react using rollup.

Intended outcome:
Apollo client should bundle and load.

Actual outcome:

The loading fails at runtime with Uncaught ReferenceError: require is not defined.

This is due to

return React || (React = require('react'));

image

It might be better to use import instead of require.

How to reproduce the issue:

Use rollup for building the app (using apollo-client/react).
PS: Set the output format to es. (Fails with 'cjs' too)

Versions

Apollo-client: 3.0-beta.38 (React)

@ashubham ashubham changed the title Uncaught ReferenceError: require is not defined [3.0-beta] Uncaught ReferenceError: require is not defined Mar 9, 2020
@ashubham
Copy link
Author

@benjamn @hwillson Any guidance here ?

@hwillson
Copy link
Member

@ashubham can you provide a small runnable reproduction that demonstrates the issue you're seeing with Rollup? We have an AC3 non-React Rollup based example here that demonstrates how this can be achieved with Rollup.

hwillson added a commit that referenced this issue May 29, 2020
to help prevent modern bundlers from requiring React when used
with `@apollo/client/core` (in other words, without any of
Apollo Client's React components). While this approach works
well for applications that aren't using React, it introduces
problems for bundlers and applications that are using React
(as outlined in #6035 and #6352). There are several different ways
we can address this, and we might do something more substantial
in the future, but for now this commit manipulates Apollo Client's
core CJS bundle at build time, to make the React require optional.

Fixes #6035.
Fixes #6352.
hwillson added a commit that referenced this issue May 29, 2020
PR #5577 introduced a new way of lazily loading React
to help prevent modern bundlers from requiring React when used
with `@apollo/client/core` (in other words, without any of
Apollo Client's React components). While this approach works
well for applications that aren't using React, it introduces
problems for bundlers and applications that are using React
(as outlined in #6035 and #6352). There are several different ways
we can address this, and we might do something more substantial
in the future, but for now this commit manipulates Apollo Client's
core CJS bundle at build time, to make the React require optional.

Fixes #6035.
Fixes #6352.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants