andresBeltran
andresBeltran•2y ago

Hello everyone I have set up an app with

Hello everyone. I have set up an app with Convex or the first time (it was super easy). However, I'm trying to deploy with netlify now, and since my app is built with Next, I use the build command npx convex deploy && next build. However, the build keeps failing due to the build command . Would this be the right command to use?
24 Replies
ari
ari•2y ago
Hey there! Could you share the error message you're seeing? Just looking at the command you shared, it seems reasonably correct, but I can help debug 🙂
andresBeltran
andresBeltranOP•2y ago
Hi 🤚 , it might not have to do with convex, but I just wanted to check here. Thank you for your kindness offering to take a look. Here is the error I see on netlify: 2:18:50 PM: $ npx convex deploy && next build 2:18:50 PM: Detected Next.js project. 2:18:50 PM: ? Create a .env file and add NEXT_PUBLIC_CONVEX_URL to save prod URL? (Y/n) ​ 2:18:50 PM: "build.command" failed 2:18:50 PM: ──────────────────────────────────────────────────────────────── 2:18:50 PM: ​ 2:18:50 PM: Error message 2:18:50 PM: Command failed with exit code 130: npx convex deploy && next build (https://ntl.fyi/exit-code-130) 2:18:50 PM: ​ 2:18:50 PM: Error location 2:18:50 PM: In Build command from Netlify app: 2:18:50 PM: npx convex deploy && next build 2:18:50 PM: ​ 2:18:50 PM: Resolved config 2:18:50 PM: build: 2:18:50 PM: command: npx convex deploy && next build 2:18:50 PM: commandOrigin: ui 2:18:50 PM: environment: 2:18:50 PM: - CONVEX_DEPLOY_KEY 2:18:50 PM: - NEXT_PRIVATE_TARGET 2:18:50 PM: publish: /opt/build/repo/.next 2:18:50 PM: publishOrigin: ui 2:18:50 PM: plugins: 2:18:50 PM: - inputs: {} 2:18:50 PM: origin: ui 2:18:50 PM: package: '@netlify/plugin-nextjs'
Indy
Indy•2y ago
IIUC I think you need to check in the .env file in your git repository your Netlify project is pulling from @ballingt for double checking this
andresBeltran
andresBeltranOP•2y ago
Thank you @Indy . I do have a .env with the NEXT_PUBLIC_CONVEX_URL variable provided by convex. However, I think that variable is not accesible to Netlify (since it lives in the gitignore) I thought that the Deploy key provided by convex was enough.
ari
ari•2y ago
If you have your .env gitignored, you could also copy the value from your .env to your Netlify env vars
andresBeltran
andresBeltranOP•2y ago
Oh, I see. I'll give it a try. Thanks again
ari
ari•2y ago
Let me know how it goes! We've been typically recommending to check .env in to git and not .gitignore it, as @Indy recommended, though. Were you already using .env for other purposes before adding Convex in?
andresBeltran
andresBeltranOP•2y ago
Will do. I wasn't using .env for anything else before adding Convex.
ballingt
ballingt•2y ago
IIUC I think you need to check in the .env file in your git repository your Netlify project is pulling from
Yeah confirming this is the flow we suggest for Next.js, since Next.js recommends checking in the .env file — but providing the environment variable in Netlify works well too. E.g. Remix does not suggest checking in the .env file, so for Remix we suggest entering the envvar directly in Netlify. Either of these should work though.
andresBeltran
andresBeltranOP•2y ago
Thank you very much. I tried adding the variable directly on Netlify, I'm still getting a build error, but the new variable appears under "environment" 2:51:59 PM: Resolved config 2:51:59 PM: build: 2:51:59 PM: command: npx convex deploy && next build 2:51:59 PM: commandOrigin: ui 2:51:59 PM: environment: 2:51:59 PM: - CONVEX_DEPLOY_KEY 2:51:59 PM: ** - NEXT_PUBLIC_CONVEX_URL** 2:51:59 PM: - NEXT_PRIVATE_TARGET 2:51:59 PM: publish: /opt/build/repo/.next 2:51:59 PM: publishOrigin: ui 2:51:59 PM: plugins: 2:51:59 PM: - inputs: {} 2:51:59 PM: origin: ui 2:51:59 PM: package: '@netlify/plugin-nextjs'
ballingt
ballingt•2y ago
Sorry for the delay, what's the build error @andresBeltran? You do need both of these, NEXT_PUBLIC_CONVEX_URL (for the frontend to know where to talk to) and CONVEX_DEPLOY_KEY (to deploy your Convex functions)
andresBeltran
andresBeltranOP•2y ago
No worries Tom, thank you for getting back to me. I do have both of those variables, the error I get is 2:18:50 PM: Error message 2:18:50 PM: Command failed with exit code 130: npx convex deploy && next build (https://ntl.fyi/exit-code-130) 2:18:50 PM: ​ 2:18:50 PM: Error location 2:18:50 PM: In Build command from Netlify app: 2:18:50 PM: npx convex deploy && next build Thank you very much for your help. I have to be away from my pc for a few hours, but I might ask again afterwards. Thank you again!🤚
ari
ari•2y ago
Hm, seems nondescript. Was there more logging above/below this error? We could also try isolating the error by temporarily changing the build command to next build (without convex deployment) to see if it has to do with Convex deployment or the next build itself
andresBeltran
andresBeltranOP•2y ago
I see. I tried isolating the issue and using only next build, and it work, the app was deployed successfully. The full log that I get when combining npx convex deploy with next build goes like this:
andresBeltran
andresBeltranOP•2y ago
`3:25:39 PM: 2. Build command from Netlify app
3:25:39 PM: ──────────────────────────────────────────────────────────────── 3:25:39 PM: ​ 3:25:39 PM: $ npx convex deploy && next build 3:25:40 PM: Detected Next.js project. 3:25:40 PM: ? Create a .env file and add NEXT_PUBLIC_CONVEX_URL to save prod URL? (Y/n) ​ 3:25:40 PM: "build.command" failed
3:25:40 PM: ──────────────────────────────────────────────────────────────── 3:25:40 PM: ​ 3:25:40 PM: Error message 3:25:40 PM: Command failed with exit code 130: npx convex deploy && next build (https://ntl.fyi/exit-code-130) 3:25:40 PM: ​ 3:25:40 PM: Error location 3:25:40 PM: In Build command from Netlify app: 3:25:40 PM: npx convex deploy && next build 3:25:40 PM: ​ 3:25:40 PM: Resolved config 3:25:40 PM: build: 3:25:40 PM: command: npx convex deploy && next build 3:25:40 PM: commandOrigin: ui 3:25:40 PM: environment: 3:25:40 PM: - CONVEX_DEPLOY_KEY 3:25:40 PM: - NEXT_PUBLIC_CONVEX_URL 3:25:40 PM: - NEXT_PRIVATE_TARGET 3:25:40 PM: publish: /opt/build/repo/.next 3:25:40 PM: publishOrigin: ui 3:25:40 PM: plugins: 3:25:40 PM: - inputs: {} 3:25:40 PM: origin: ui 3:25:40 PM: package: '@netlify/plugin-nextjs'
Search results for '"non-zero exit code: 130"' - Netlify Support Fo...
Ask questions, share solutions, and get to know the Netlify community.
andresBeltran
andresBeltranOP•2y ago
`3:25:40 PM: Caching artifacts 3:25:40 PM: Started saving node modules 3:25:40 PM: Finished saving node modules 3:25:41 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2) 3:25:40 PM: Started saving build plugins 3:25:40 PM: Finished saving build plugins 3:25:40 PM: Started saving corepack cache 3:25:40 PM: Finished saving corepack cache 3:25:40 PM: Started saving pip cache 3:25:40 PM: Finished saving pip cache 3:25:40 PM: Started saving emacs cask dependencies 3:25:40 PM: Finished saving emacs cask dependencies 3:25:40 PM: Started saving maven dependencies 3:25:40 PM: Finished saving maven dependencies 3:25:40 PM: Started saving boot dependencies 3:25:40 PM: Finished saving boot dependencies 3:25:40 PM: Started saving rust rustup cache 3:25:40 PM: Finished saving rust rustup cache 3:25:40 PM: Started saving go dependencies 3:25:40 PM: Finished saving go dependencies 3:25:41 PM: Build failed due to a user error: Build script returned non-zero exit code: 2 3:25:41 PM: Failing build: Failed to build site 3:25:41 PM: Finished processing build request in 19.594s``
Search results for '"non-zero exit code: 2"' - Netlify Support Forums
Ask questions, share solutions, and get to know the Netlify community.
ballingt
ballingt•2y ago
@andresBeltran OK I know what is is then! Could you change your build command to add --no-save-url to the Convex command I've got a fix in for the next Convex release that will make this unnecessary, but right now it's asking you if you want to save the production CONVEX_URL in your .env file, which is silly because you're not there to type yes or no ...because it's a deploy
andresBeltran
andresBeltranOP•2y ago
lol, yes that makes sense. Just making sure, it will be npx convex deploy && next build --no-save-url
ballingt
ballingt•2y ago
ah sorry npx convex deploy --no-save-url && next build
andresBeltran
andresBeltranOP•2y ago
That looks really promising, something has changed, but I don't understand it quite well. The new error is : Deploying to https://quaint-walrus-678.convex.cloud... 11:03:52 PM: Temporary directory '/tmp' and project directory 'convex/_generated' are on different filesystems. 11:03:53 PM: If you're running into errors with other tools watching the project directory, override the temporary directory location with the CONVEX_TMPDIR environment variable. Be sure to pick a temporary directory that's on the same filesystem as your project. - Checking for changed table indexes... 11:03:54 PM: ✖ Error: Unable to build indexes on https://quaint-walrus-678.convex.cloud 11:03:54 PM: ✖ Checking for changed table indexes... 11:03:54 PM: 403 Forbidden: BadAdminKey: The provided admin key was invalid for this instance 11:03:54 PM: ​ 11:03:54 PM: "build.command" failed 11:03:54 PM: ──────────────────────────────────────────────────────────────── 11:03:54 PM: ​ 11:03:54 PM: Error message 11:03:54 PM: Command failed with exit code 1: npx convex deploy --no-save-url && next build (https://ntl.fyi/exit-code-1) 11:03:54 PM: ​ 11:03:54 PM: Error location 11:03:54 PM: In Build command from Netlify app: 11:03:54 PM: npx convex deploy --no-save-url && next build
ballingt
ballingt•2y ago
Oh we've seen this, yes just a sec ok cool, the part to focus on is
BadAdminKey: The provided admin key was invalid for this instance
You have two convex deployments, and you're probably deploying to your production instance
ballingt
ballingt•2y ago
No description
ballingt
ballingt•2y ago
The CONVEX_DEPLOY_KEY when deploying should be the deploy key for the production deployment
andresBeltran
andresBeltranOP•2y ago
My bad, I should have paid attention to that detail. Thank you and the team again for all you support, is finally deployed! I can't believe that I am looking at my app working with a database for real and logging with auth0! This is quite remarkable!

Did you find this page helpful?