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

The esm version of @google-cloud/tasks is incorrectly using require to load a JSON file #5702

Closed
7 tasks done
timomeh opened this issue Sep 23, 2024 · 6 comments
Closed
7 tasks done

Comments

@timomeh
Copy link

timomeh commented Sep 23, 2024

Please make sure you have searched for information in the following guides.

A screenshot that you have tested with "Try this API".

n/a — a code issue with the esm version

Link to the code that reproduces this issue. A link to a public Github Repository or gist with a minimal reproduction.

https://gist.github.com/timomeh/1744248097efe05a3a6671e8c1af1ea8

A step-by-step description of how to reproduce the issue, based on the linked reproduction.

  1. Create an empty Next.js v14 app and install @google-cloud/tasks
  2. Copy the route handler from the gist and the next.config.js
  3. Run next build (ensure it's using the standalone output)
  4. Start the built app
  5. Try to call the route handler

A clear and concise description of what the bug is, and what you expected to happen.

Following the above steps, it should work and enqueue a task, but instead it errors with:

Error: Cannot find module '/app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@google-cloud/tasks/build/esm/src/v2/cloud_tasks_client_config.json'

If you compare the contents of the directories /node_modules/@google-cloud/tasks/build/esm/src/v2/ with .next/standalone/node_modules/@google-cloud/tasks/build/esm/src/v2/, you can see that the standalone output is missing the cloud_tasks_client_config.json file.

A clear and concise description WHY you expect this behavior, i.e., was it a recent change, there is documentation that points to this behavior, etc. **

The esm package imports the file json-helper.cjs, which uses require() to load the file cloud_tasks_client_config.json. ESM can't use require().

Because of this, the standalone build of Next.js won't copy over the cloud_tasks_client_config.json file. Without this file, the SDK errors.

A quickfix is to not use the esm version, by loading the SDK with require('@google-cloud/tasks') instead of import

Copy link
Contributor

Issue was opened with an invalid reproduction link. Please make sure the repository is a valid, publicly-accessible github repository, and make sure the url is complete (example: https://github.com/googleapis/google-cloud-node)

@timomeh
Copy link
Author

timomeh commented Sep 23, 2024

What? I entered the reproduction link, it's a public gist, the issue template says "or gist"!

@timomeh
Copy link
Author

timomeh commented Sep 23, 2024

@sofisl If Gists aren't allowed as reproduction step, the issue template needs to be updated. It's not a great experience for someone to take the time and prepare an issue description, just for a bot to close it.

@sofisl
Copy link
Contributor

sofisl commented Sep 23, 2024

@timoneh thanks for the call-out, noticed a small issue with our regex that I've updated here: #5705. I've confirmed and it would have let your issue come through. That being said, this issue does look like this one, it seems to be an issue with the way Next copies over files. Can you try this workaround?

@timomeh
Copy link
Author

timomeh commented Sep 23, 2024

Sorry for not seeing the already opened issue #4858, I searched the issues for "cloud_tasks_client_config" and got no results, but I didn't search for "cloud_tasks_client_config.json". 🙄 My bad.

I also already tried the outputFileTracingIncludes config, like you posted in the linked workaround. But I also encountered the same issue as in your last comment here. I'm not using turborepo tho, I'm using nx.

I'll be watching #4858 then 🙂

@sbilling
Copy link

@sofisl I've tried the workaround you've linked above with no luck.

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