googleapis / google-cloud-node

Google Cloud Client Library for Node.js
https://cloud.google.com/nodejs
Apache License 2.0
2.92k stars 595 forks source link

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 #4987

Open ollebergkvist opened 9 months ago

ollebergkvist commented 9 months ago

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(R) Core(TM) 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!

ollebergkvist commented 9 months ago

I'm getting the error also after setting node-linker=hoisted in my .npmrc file

ollebergkvist commented 9 months ago

I just tried to use turborepo with yarn with this config:

yarnrc.yml

nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-3.4.1.cjs

Same error.

jgeschwendt commented 8 months ago

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
ollebergkvist commented 8 months ago

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'"

h36ahmed commented 8 months ago

I am running into the same issue 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-analytics+data@4.4.0/node_modules/@google-analytics/data/build/src/v1alpha/alpha_analytics_data_client.js ../../node_modules/.pnpm/@google-analytics+data@4.4.0/node_modules/@google-analytics/data/build/src/v1alpha/index.js ../../node_modules/.pnpm/@google-analytics+data@4.4.0/node_modules/@google-analytics/data/build/src/index.js ./src/app/api/analytics/route.ts ⚠ ../../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'

Naruto1200 commented 7 months ago

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

alexxisroxxanne commented 7 months ago

I am also getting this issue while trying to use Document AI:

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

Import trace for requested module:
./node_modules/.pnpm/google-gax@4.3.2/node_modules/google-gax/build/src/streamingRetryRequest.js
./node_modules/.pnpm/google-gax@4.3.2/node_modules/google-gax/build/src/streamingCalls/streaming.js
./node_modules/.pnpm/google-gax@4.3.2/node_modules/google-gax/build/src/index.js
./node_modules/.pnpm/@google-cloud+documentai@8.2.0/node_modules/@google-cloud/documentai/build/src/v1beta1/document_understanding_service_client.js
./node_modules/.pnpm/@google-cloud+documentai@8.2.0/node_modules/@google-cloud/documentai/build/src/v1beta1/index.js
./node_modules/.pnpm/@google-cloud+documentai@8.2.0/node_modules/@google-cloud/documentai/build/src/index.js
./src/
ollebergkvist commented 7 months ago

@sofisl Hi! Hope you're well. Is there an ETA for when we might see a fix here? Many thanks in advance 🙏

dstroot commented 7 months ago

Has anyone tried just installing request? E.g. "pnpm add request"? It worked for me, although request is a long deprecated module.

ollebergkvist commented 7 months ago

Has anyone tried just installing request? E.g. "pnpm add request"? It worked for me, although request is a long deprecated module.

Yepp, the missing modules stack continues... at least for @google-cloud/tasks but I guess for some of the libs that might be a sufficient fix.

sofisl commented 7 months ago

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

sofisl commented 7 months ago

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?)
kofron commented 5 months ago

@sofisl I have this issue too - it doesn't cause any runtime issues but it clutters up my console with a lot of distracting warnings. Can you describe your module resolution workaround so I can try that?

I'm using @google-cloud/documentai ^8.8.0 and this is the runtime warning:

image
sofisl commented 5 months ago

@kofron can you elaborate on your environment? Are you using Next.js?

I think this is a bundling issue with next.js. This seems related, could you try installing request as well. It seems Next.js doesn't bundle this dependency for some reason.