amianthus
amianthus7d ago

Can't deploy to Vercel with Next.js

When I push to vercel and it runs the "npx convex deploy --cmd 'bun run build'", it keeps giving me nextjs's node api errors and telling me to add use node directives but thats for the frontend no?
node_modules/next/dist/compiled/gzip-size/index.js:1:2840:
1 │ ...use strict";e.exports=require("fs")},781:e=>{"use strict";e.expo...
╵ ~~~~
The package "fs" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
✘ [ERROR] Could not resolve "stream"
node_modules/next/dist/compiled/gzip-size/index.js:1:2886:
1 │ ...e strict";e.exports=require("stream")},796:e=>{"use strict";e.ex...
╵ ~~~~~~~~
The package "stream" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
✘ [ERROR] Could not resolve "zlib"
node_modules/next/dist/compiled/gzip-size/index.js:1:2936:
1 │ ...se strict";e.exports=require("zlib")}};var r={};function __nccwp...
╵ ~~~~~~
The package "zlib" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
✖ It looks like you are using Node APIs from a file without the "use node" directive.
See https://docs.convex.dev/functions/runtimes#nodejs-runtime
node_modules/next/dist/compiled/gzip-size/index.js:1:2840:
1 │ ...use strict";e.exports=require("fs")},781:e=>{"use strict";e.expo...
╵ ~~~~
The package "fs" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
✘ [ERROR] Could not resolve "stream"
node_modules/next/dist/compiled/gzip-size/index.js:1:2886:
1 │ ...e strict";e.exports=require("stream")},796:e=>{"use strict";e.ex...
╵ ~~~~~~~~
The package "stream" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
✘ [ERROR] Could not resolve "zlib"
node_modules/next/dist/compiled/gzip-size/index.js:1:2936:
1 │ ...se strict";e.exports=require("zlib")}};var r={};function __nccwp...
╵ ~~~~~~
The package "zlib" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
✖ It looks like you are using Node APIs from a file without the "use node" directive.
See https://docs.convex.dev/functions/runtimes#nodejs-runtime
I added "use node" to my convex routes anyways but still nothing works
6 Replies
Convex Bot
Convex Bot7d ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
erquhart
erquhart7d ago
You're probably importing something from one of your nextjs node api files into a convex file, or from a file that imports from one of those files somewhere up the chain.
amianthus
amianthusOP7d ago
ok i got that to work, but does convex currently support a vercel build cache? it seems like if i redeploy with changed env keys or whatever non-code base change it is, it wont use the build cache
erquhart
erquhart7d ago
Convex cli shouldn't change the behavior of what bun run build does as far as I know. If you're seeing this any details you have would be helpful.
amianthus
amianthusOP7d ago
Sentry doing its stuff is expected - but as you can see "bun run build" is being executed again Without convex, the cmd "bun run build" wont actually be executed at all on vercel, it will recognise it was already ran prior and ignore that. With convex, because npx convex deploy is actively executing the cmd "bun run build", it makes sense for it to run twice But what I wanted to happen was "npx convex deploy --cmd "bun run build" to not execute at all. just like prior to not having convex Vercel should detect the inputs havent changed, so nor should the outputs Not sure if this is a convex or vercel issue, but I hope this stuff helps
erquhart
erquhart7d ago
If your build command is npx convex deploy --cmd "bun run build" and nothing more, it won't run twice. So that second run is coming from somewhere else. Vercel's build caching shouldn't behave any differently with Convex in use.

Did you find this page helpful?