Cannot access $DEPLOY_URL with netlify build


I am using Nuxt in a new project and deploy it as a static site through the nuxt generate command.
I’m also using the nuxt-http module which requires absolute URLs.

I try to set the baseURL based on environment variables given by Netlify: $URL and $DEPLOY_URL.

My netlify.toml file is the following:

command = 'nuxt generate'
publish = "./dist"
functions = "./functions"

command = 'BASE_URL=$URL nuxt generate'

command = 'BASE_URL=$DEPLOY_URL nuxt generate'

command = 'nuxt'
autoLaunch = false

When I run netlify deploy, it skips the build step, which is maybe intentional.

When I run netlify build, the context is always production and never deploy-preview.

How can I pass $DEPLOY_URL to my build step? How to link build and deploy steps?

Besides, the $URL env variable does not start with https whereas a certificate was created in the Netlify admin.

Thanks for your help.

I read the following resources before asking:

We really recommend people NOT use absolute URL’s for exactly reasons like this; use only /, and then the site is portable to run locally or at any URL you might access it at. Does that really not work for nuxt, or just your special config?

Regardless, we can try to help troubleshoot.

Running netlify build locally may not get you the URL you want since of course WE set $URL only in our build env (maybe you set it locally, not sure), but in our CI, does that not work as expected? I have had some spotty luck using a VAR=value command prefix like that; might try instead something like: nuxt generate -DBASE_URL=$URL since that will mean the shell can’t get in the way of getting that value through to your build command. Of course nuxt has to “do the right thing” there - and not sure it has such facilities, but hopefully you know a trick there :slight_smile:

OK, it seems that my real issue comes from using absolute URLs when I don’t need them. Thank you for pointing me to the right direction.

1 Like

Actually, I better understand my mistake. Since I use nuxt-generate to build the static site, there are parts of my code that rely on node-fetch to get content and it of course needs an absolute URL during the generation process. That’s why the logs tell me I need an absolute URL.

As of now, I inject the URL I need in the command as follows:

command = 'BASE_URL=$URL yarn generate'

command = 'BASE_URL=$DEPLOY_PRIME_URL yarn generate'

And reuse it in my Nuxt config or the localhost URL in dev mode:

const baseURL = process.env.BASE_URL || 'http://localhost:3000'

export default {
  http: {

And even with this config, it means my functions must be published on Netlify so that they are used during the generation process in production mode.

I read the Nuxt team is working on a full static mode and a way to better work with services like Netlify, out of the box. Can’t wait.

1 Like

thanks for sharing this, @lucpotage!

Somewhat related to this… here is my netlify.toml


This configuration was working and recently stopped working. The DEPLOY_URL variable doesn’t appear to be setting in the environment variables. Instead, the actual template literal “$DEPLOY_URL” is being set as the environment variables now.

Any idea why this is happening? How can I set netlify deploy-url variables as env vars before the build start?

I took a look at this thread and found a solution:

REACT_APP_LOGOUT_URL=$DEPLOY_URL/v2/logout && npm run build"
1 Like

In case it helps new users, I now install netlify-plugin-contextual-env. It solved all my issues.

Here is part of my .toml file:

package = 'netlify-plugin-contextual-env'
  mode = 'suffix'

Let’s say I have this var in my deploy settings:


I also add a variant with a suffix corresponding to my next deploy branch:


And I have a local .env file with:


This way, I can have fully qualified URLs in all my contexts.

1 Like