google-cloud-node: Module not found: Can't resolve 'request' in '/vercel/path0/node_modules/.pnpm/google-gax@4.2.1_encoding@0.1.13/node_modules/google-gax/build/src

I’m getting this error during build time using @google-cloud/tasks in a turborepo(monorepo).

It seems to be directly related to pnpm, I’m using @google-cloud/tasks in another Vercel project which uses yarn, and the error is not triggered during build in this case.

Is pnpm supported?

next:build:  ⚠ Compiled with warnings

next:build: 

next:build: ../../node_modules/.pnpm/google-gax@4.2.1_encoding@0.1.13/node_modules/google-gax/build/src/streamingRetryRequest.js

next:build: Module not found: Can't resolve 'request' in '/vercel/path0/node_modules/.pnpm/google-gax@4.2.1_encoding@0.1.13/node_modules/google-gax/build/src'

next:build: 

next:build: Import trace for requested module:

next:build: ../../node_modules/.pnpm/google-gax@4.2.1_encoding@0.1.13/node_modules/google-gax/build/src/streamingRetryRequest.js

next:build: ../../node_modules/.pnpm/google-gax@4.2.1_encoding@0.1.13/node_modules/google-gax/build/src/streamingCalls/streaming.js

next:build: ../../node_modules/.pnpm/google-gax@4.2.1_encoding@0.1.13/node_modules/google-gax/build/src/index.js

next:build: ../../node_modules/.pnpm/@google-cloud+tasks@4.0.1_encoding@0.1.13/node_modules/@google-cloud/tasks/build/src/v2beta2/cloud_tasks_client.js

next:build: ../../node_modules/.pnpm/@google-cloud+tasks@4.0.1_encoding@0.1.13/node_modules/@google-cloud/tasks/build/src/v2beta2/index.js

next:build: ../../node_modules/.pnpm/@google-cloud+tasks@4.0.1_encoding@0.1.13/node_modules/@google-cloud/tasks/build/src/index.js

next:build: ./app/api/crons/prepare-monitor/route.ts

Environment details

System: OS: macOS 12.7.2 CPU: (6) x64 Intel® Core™ i5-8500B CPU @ 3.00GHz Memory: 1.29 GB / 32.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 18.18.2 - ~/.asdf/installs/nodejs/lts/bin/node npm: 9.8.1 - ~/.asdf/plugins/nodejs/shims/npm pnpm: 8.11.0 - ~/.asdf/installs/nodejs/lts/bin/pnpm Browsers: Chrome: 120.0.6099.234 Safari: 17.2.1 npmPackages: @google-cloud/tasks: ^4.0.1 => 4.0.1

Steps to reproduce

Please include any and all code and/or steps related to reproducing the bug.

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 15 (3 by maintainers)

Most upvoted comments

For @google-cloud/tasks it’s more complicated, it just continues with more modules missing after installing request eg: “Error: Cannot find module ‘/app/node_modules/.pnpm/@google-cloud+tasks@5.1.1_encoding@0.1.13/node_modules/@google-cloud/tasks/build/esm/src/v2/cloud_tasks_client_config.json’”

I hit this today, I’m using pnpm@v8 in a monorepo, running node@v20.11.0, pkg details are

"@google-cloud/recaptcha-enterprise": "5.3.0",
"next": "14.1.0"

stack:

../../node_modules/.pnpm/google-gax@4.3.1/node_modules/google-gax/build/src/streamingRetryRequest.js
Module not found: Can't resolve 'request' in '~/node_modules/.pnpm/google-gax@4.3.1/node_modules/google-gax/build/src'

Import trace for requested module:
../../node_modules/.pnpm/google-gax@4.3.1/node_modules/google-gax/build/src/streamingRetryRequest.js
../../node_modules/.pnpm/google-gax@4.3.1/node_modules/google-gax/build/src/streamingCalls/streaming.js
../../node_modules/.pnpm/google-gax@4.3.1/node_modules/google-gax/build/src/index.js
../../node_modules/.pnpm/@google-cloud+recaptcha-enterprise@5.3.0/node_modules/@google-cloud/recaptcha-enterprise/build/src/v1beta1/recaptcha_enterprise_service_v1_beta1_client.js
../../node_modules/.pnpm/@google-cloud+recaptcha-enterprise@5.3.0/node_modules/@google-cloud/recaptcha-enterprise/build/src/v1beta1/index.js
../../node_modules/.pnpm/@google-cloud+recaptcha-enterprise@5.3.0/node_modules/@google-cloud/recaptcha-enterprise/build/src/index.js

Ok after looking into this, there are two separate issues happening:

  1. The issue with Cloud Tasks and Next.js is a known issue with a workaround, please see here.
  2. We don’t technically support pnpm because there are some discrepancies in how it installs modules (for example, not implicitly installing the highest version of a dependency with a caret). That being said, we actually use pnpm to install dependencies during tests, so this seemed a little weird to me. Since tests haven’t failed, I attempted to reproduce with Node 18 and pnpm 8.6.10 locally, and was able to run our sample test successfully (after fixing some issues with the module resolution as described here). Are any of these issues occuring in just a Nodejs environment (without Vercel or Next.js?)

Sorry for the delay, I will take a look next week.

I’m also running into this problem with the google tasks library for node

Error: Cannot find module 'node_modules\@google-cloud\tasks\build\esm\src\v2\cloud_tasks_client_config.json'

I do not get this error if i downgrade to version 5.0.0. but anythging beyond this version triggers the error. I’m using NextJS 14