Error: Cannot find module Next.js 14 when module exists #64765
-
SummaryI get this error in dev mode and when building my Next.js app locally or on Vercel, but also in dev mode. Error: Cannot find module 'C:\Projects\project\node_modules@google-cloud\tasks\build\esm\src\v2\cloud_tasks_client_config.json' Here is what I have tried:
Here is a minimal reproduce of the problem: My next.config.mjs doesn't contain any webpack configurations. Here is the package.json: When I click on the 'C:\Projects\project\node_modules@google-cloud\tasks\build\esm\src\v2\cloud_tasks_client_config.json file, it leads me to the right json file inside of node_modules, so the file exists. Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 2 replies
-
|
After I have tried multiple versions of I even played around with the Changing the This module always seems to have issues, I recommend staying away from it. to fix this, run:
|
Beta Was this translation helpful? Give feedback.
-
|
wow, ty ty ty |
Beta Was this translation helpful? Give feedback.
-
|
any updates on this? i assume it's just the import routes are a bit off so you kind of need to copy this file over to root during the build process |
Beta Was this translation helpful? Give feedback.
-
|
I have the same issue with "@google-cloud/tasks": "5.1.0" and "next": "15.3.0-canary.10". Locally everything works fine, but on Vercel it breaks with Error: ENOENT: no such file or directory, open '/vercel/path0/node_modules/@google-cloud/tasks/build/esm/src/v2/cloud_tasks_client_config.json' |
Beta Was this translation helpful? Give feedback.
-
|
This workaround is currently working for me: task file: next.config.js: |
Beta Was this translation helpful? Give feedback.
-
|
based on #64765 (comment) const nextConfig = {
webpack: (config, { isServer }) => {
if (isServer) {
config.externals = [...(config.externals || []), "@google-cloud/tasks"];
}
return config;
},
}; |
Beta Was this translation helpful? Give feedback.
-
|
Next.js bundle Server Components, Route handlers and Server Actions (Actions are not documented but I got the same error in it). To fix this, you can use the const nextConfig = {
serverExternalPackages: ["@google-cloud/tasks"],
}https://nextjs.org/docs/app/api-reference/config/next-config-js/serverExternalPackages |
Beta Was this translation helpful? Give feedback.
After I have tried multiple versions of
Next.jsand multiple different versions of@google-cloud/tasks, the issue persisted locally and on Vercel.I even played around with the
next.config.mjswebpack config, and cleared cache, and deletednode_modulesmultiple times.Changing the
@google-cloud/tasksversion to5.1.0fixed the issue.This module always seems to have issues, I recommend staying away from it. to fix this, run:
npm i @google-cloud/[email protected]