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

TypeError: module.require is not a function error when running with turbopack #8004

Open
sam-btrt opened this issue Dec 17, 2024 · 3 comments

Comments

@sam-btrt
Copy link

Issue Description

Apologies if this should be an FR, or an issue on a different project. I'm finding it hard to work out if nextjs + turbopack + apollo server is supposed to be supported or not, and what's stopping it from working at the moment.

In any case, when trying to run next dev --turbo on a project with apollo server, I get a bunch of TypeError: module.require is not a function errors whenever the gql endpoint is hit, and no data is returned. Running without --turbo (i.e. using webpack) works fine.

Related issues:
apollo-server-integrations/apollo-server-integration-next#172
apollo-server-integrations/apollo-server-integration-next#232
vercel/next.js#72573

Thanks

Link to Reproduction

See vercel/next.js#72573

Reproduction Steps

See vercel/next.js#72573

@glasser
Copy link
Member

glasser commented Dec 19, 2024

I wanted to look into this, but when I checked out @MersadHabibi's linked repo and ran npm i I got this:

npm error code ERESOLVE
npm error ERESOLVE could not resolve
npm error
npm error While resolving: react-hook-form@7.53.2
npm error Found: react@19.0.0-rc-66855b96-20241106
npm error node_modules/react
npm error   react@"19.0.0-rc-66855b96-20241106" from the root project
npm error   peerOptional react@"^16.8.0 || ^17.0.0 || ^18.0.0 || >=19.0.0-rc <19.0.0" from @apollo/client@3.11.9
npm error   node_modules/@apollo/client
npm error     @apollo/client@"^3.11.9" from the root project
npm error   5 more (lucide-react, next, react-dom, rehackt, styled-jsx)
npm error
npm error Could not resolve dependency:
npm error peer react@"^16.8.0 || ^17 || ^18 || ^19" from react-hook-form@7.53.2
npm error node_modules/react-hook-form
npm error   react-hook-form@"^7.53.2" from the root project
npm error   peer react-hook-form@"^7.0.0" from @hookform/resolvers@3.9.1
npm error   node_modules/@hookform/resolvers
npm error     @hookform/resolvers@"^3.9.1" from the root project
npm error
npm error Conflicting peer dependency: react@19.0.0
npm error node_modules/react
npm error   peer react@"^16.8.0 || ^17 || ^18 || ^19" from react-hook-form@7.53.2
npm error   node_modules/react-hook-form
npm error     react-hook-form@"^7.53.2" from the root project
npm error     peer react-hook-form@"^7.0.0" from @hookform/resolvers@3.9.1
npm error     node_modules/@hookform/resolvers
npm error       @hookform/resolvers@"^3.9.1" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.

I'd be happy to look in more detail given a full detailed reproduction that requires no creativity on my part. Though it does seem likely that this is just some overzealous optimization on "turbopack"'s part?

@glasser glasser closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2024
@glasser
Copy link
Member

glasser commented Dec 19, 2024

That said, I see createHash in the error messages, which makes me suspect this is related to @apollo/utils.createhash. Looking here, it seems that that package does call module.require after trying to guess if we're in Node. I guess something about this "turbo mode" makes an environment that's kinda but not really like normal Node. Maybe this is fixable.

@glasser glasser reopened this Dec 19, 2024
glasser added a commit to apollographql/apollo-utils that referenced this issue Dec 19, 2024
Apparently Next.JS "Turbopack" runs code in a weird semi-Node
environment that doesn't have module.require. We don't want to call
require directly because that makes other bundlers put in polyfills. So
make Turbopack use sha.js instead of just throwing. Non-ideal
but better than what we have today.

For apollographql/apollo-server#8004
@MersadHabibi
Copy link

I wanted to look into this, but when I checked out @MersadHabibi's linked repo and ran npm i I got this:

npm error code ERESOLVE
npm error ERESOLVE could not resolve
npm error
npm error While resolving: react-hook-form@7.53.2
npm error Found: react@19.0.0-rc-66855b96-20241106
npm error node_modules/react
npm error   react@"19.0.0-rc-66855b96-20241106" from the root project
npm error   peerOptional react@"^16.8.0 || ^17.0.0 || ^18.0.0 || >=19.0.0-rc <19.0.0" from @apollo/client@3.11.9
npm error   node_modules/@apollo/client
npm error     @apollo/client@"^3.11.9" from the root project
npm error   5 more (lucide-react, next, react-dom, rehackt, styled-jsx)
npm error
npm error Could not resolve dependency:
npm error peer react@"^16.8.0 || ^17 || ^18 || ^19" from react-hook-form@7.53.2
npm error node_modules/react-hook-form
npm error   react-hook-form@"^7.53.2" from the root project
npm error   peer react-hook-form@"^7.0.0" from @hookform/resolvers@3.9.1
npm error   node_modules/@hookform/resolvers
npm error     @hookform/resolvers@"^3.9.1" from the root project
npm error
npm error Conflicting peer dependency: react@19.0.0
npm error node_modules/react
npm error   peer react@"^16.8.0 || ^17 || ^18 || ^19" from react-hook-form@7.53.2
npm error   node_modules/react-hook-form
npm error     react-hook-form@"^7.53.2" from the root project
npm error     peer react-hook-form@"^7.0.0" from @hookform/resolvers@3.9.1
npm error     node_modules/@hookform/resolvers
npm error       @hookform/resolvers@"^3.9.1" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.

I'd be happy to look in more detail given a full detailed reproduction that requires no creativity on my part. Though it does seem likely that this is just some overzealous optimization on "turbopack"'s part?

use npm i --legacy-peer-deps or npm i --force

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

No branches or pull requests

3 participants