google-cloud-node: `@google-cloud/tasks` 4.1.0 causes cloud_tasks_client_config.json `no such file or directory` (publish esm)

The following error happens with @google-cloud/tasks after updating from 4.0.1 to 4.1.0:

Error: ENOENT: no such file or directory, open '/vercel/path0/fuu/node_modules/.pnpm/@google-cloud+tasks@4.1.0_encoding@0.1.13/node_modules/@google-cloud/tasks/build/esm/src/v2/cloud_tasks_client_config.json'
    at Object.openSync (node:fs:603:3)
    at Object.readFileSync (node:fs:471:35)
    at 64300 (/var/task/fuu/.next/server/app/app/api/site/route.js:1:1998)
    at t (/var/task/fuu/.next/server/webpack-runtime.js:1:143)
    at __webpack_exec__ (/var/task/fuu/.next/server/app/app/api/route.js:57:72254)
    at /var/task/fuu/.next/server/app/app/api/route.js:57:72374
    at t.X (/var/task/fuu/.next/server/webpack-runtime.js:1:1285)
    at /var/task/fuu/.next/server/app/app/api/route.js:57:72340
    at Object.<anonymous> (/var/task/fuu/.next/server/app/app/api/route.js:57:72435)
    at Module._compile (node:internal/modules/cjs/loader:1256:14) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/vercel/path0/fuu/node_modules/.pnpm/@google-cloud+tasks@4.1.0_encoding@0.1.13/node_modules/@google-cloud/tasks/build/esm/src/v2/cloud_tasks_client_config.json',
  page: '/app/api/sync'
}

This seems to be related to the only change with was made from from version 4.0.1 to version 4.1.0: https://github.com/googleapis/google-cloud-node/pull/4720

Environment details

  • which product (packages/*): @google-cloud/tasks
  • Node.js version: 18
  • npm version: pnpm

Steps to reproduce

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 9
  • Comments: 30 (9 by maintainers)

Most upvoted comments

Thanks @sofisl - unfortunately the issue persists with 5.1.1 (including following the instructions above with your reproduction repo)

Having this issue after migration to 5.0 Reverting back to forced 4.0.1 fixes the issue

Here’s what I have after doing some digging/answering some questions:

  1. @ollebergkvist, thanks for your reproduction repo. I was able to reproduce the issue successfully. During my investigation I deleted the .pnpm-lock.yaml file and re-installed it. That successfully installed the missing file, i.e.:

Screenshot 2024-06-18 at 4 15 21 PM

However, after running

cd apps/next-app && pnpm build

I still get:

Collecting page data  ...Error: Cannot find module '/Users/sofialeon/turborepo-google-cloud-tasks-issue/node_modules/.pnpm/@google-cloud+tasks@5.3.0/node_modules/@google-cloud/tasks/build/esm/src/v2/cloud_tasks_client_config.json'

I can confirm the file exists Screenshot 2024-06-18 at 4 18 03 PM

This is a pretty clear Next.js issue. I don’t know why it cannot see the file, perhaps it has something to do with turborepo. If you could submit this bug within Next.js that would be greatly appreciated.

For the time being, I’ve submitted this bug, which seems related (and perhaps would fix this issue as well): https://github.com/vercel/next.js/issues/63368

@danbrauer, the reason we made this change was to support ESM. I don’t see any other way of supporting this option in ESM.

Also, @danbrauer you’re right that we are importing it into memory in this line! Without it, we wouldn’t be able to parse the JSON later. But also, as you can see, the JSON file is imported correctly in .pnpm and turbo - for some reason, next.js doesn’t want to pick it up.

Since ESM is the future, I’d love for this issue to be brought up in the next.js community, since I think this support will be needed as we move towards the future.

Thanks @sofisl - to reproduce this issue in your example repo, we need to create a standalone build - this is what activates tracing in an attempt to create the minimum required build rather than including every file within node_modules

I’ve reproduced with your repo as follows:

  1. add output: standalone to next.config.mjs:
--- a/next.config.mjs
+++ b/next.config.mjs
@@ -1,5 +1,6 @@
 /** @type {import('next').NextConfig} */
 const nextConfig = {
+  output: "standalone",
   reactStrictMode: true,
 };
  1. generate the standalone build: npx next build

  2. run the standalone build: node .next/standalone/server.js

  3. open the index page in browser and observe the error in the server console output: Error: ENOENT: no such file or directory, open '[...]/debug-tasks-next.js/.next/standalone/node_modules/@google-cloud/tasks/build/esm/src/v2/cloud_tasks_client_config.json'

  4. additionally observe that Next.js successfully traces and copies the JSON file under the cjs build to .next/standalone/node_modules/@google-cloud/tasks/build/cjs/src/v2/cloud_tasks_client_config.json - but then imports from the esm folder, which lacks the json file.

You’ll see in the Next.js docs linked above that Next.js apparently supports manual inclusion of incorrectly omitted files; I haven’t managed to get this working (didn’t try super hard) but it may be a viable workaround, albeit Next.js-specific.

Thanks, hope this helps your investigation!

Hey @sofisl ,

import { CloudTasksClient } from "@google-cloud/tasks"

The application is a Next.js application. The package manager is pnpm and the build command next build.

Same here, stuck on 4.0.1 for now

@sofisl

After upgrading to the latest Next version, we now have the bug with yarn in the repo that was working previously (the one that is not a turborepo).

Did you open a github issue for this on Vercel? In that case can you please share the link so I can track the status please.

Many thanks in advance!

I’m having the issue, setup is pnpm 9 workspace + turbo 😬 rolled back to 4.0.1 and it works, anything above doesn’t

Closed this because at the time, the release was accidental, it should have been released as a breaking change. Reopening because it seems like it’s still an issue with the 5.0.0 release.

As a workaround, I’ve republished the ‘latest’ tag as 4.0.1. This should have been released as a breaking change. Please re-install the package at latest, it should work.