You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm seeing inconsistencies in the way that the deploy and build commands work when called as one (deploy --build) or in sequence (deploy && build).
When I run deploy --build I'm finding that the --context argument is being ignored, and my builds are always created using the cli local dev set of environment variables. On the other hand, when I run netlify build as a standalone command, I can see that the emitted build respects the context variable.
I've done some digging in the source, and can see that both the deploy command and the build command execute the same runBuild function to do the actual work of creating the build, however in the build command file there's an injectEnv command which reads the value of the context argument and populates the cachedConfig ready to be red later on during the build, whereas the deploy command file doesn't do this step first.
In the Netlify UI I've created an env var called NEXT_PUBLIC_BUILD_CONTEXT and set a different value for each context.
When I run NETLIFY_SITE_ID=*** NETLIFY_AUTH_TOKEN=*** netlify deploy --build --context=deploy-preview, then visit the site and inspect the value of window.nextjsConfig in the console, I see the value "local" I set for the dev context. Changing to different contexts has no effect. Prod deployments also carry the local value.
If I run netlify build --context=deploy-preview and then inspect the contents of the .next folder, I can see that the correct values are being build into the compiled JS files. Unfortunately, if I then run netlify deploy, due to what I assume is an unrelated bug, the deployed site always shows a 404 error, I suspect because the netlify.toml file is being incorrectly deployed and the various Next.JS SSR redirect rules aren't being deployed - I haven't had a chance to fully investigate this yet.
Describe the bug
I'm seeing inconsistencies in the way that the deploy and build commands work when called as one (
deploy --build
) or in sequence (deploy && build
).When I run
deploy --build
I'm finding that the--context
argument is being ignored, and my builds are always created using the cli local dev set of environment variables. On the other hand, when I runnetlify build
as a standalone command, I can see that the emitted build respects the context variable.I've done some digging in the source, and can see that both the deploy command and the build command execute the same
runBuild
function to do the actual work of creating the build, however in thebuild
command file there's aninjectEnv
command which reads the value of the context argument and populates the cachedConfig ready to be red later on during the build, whereas the deploy command file doesn't do this step first.Have a look at
build.ts and deploy.ts
I'm using Next.JS.
Steps to reproduce
I'm using Next.JS.
I've got an included TS file that looks a bit like this
In the Netlify UI I've created an env var called
NEXT_PUBLIC_BUILD_CONTEXT
and set a different value for each context.When I run
NETLIFY_SITE_ID=*** NETLIFY_AUTH_TOKEN=*** netlify deploy --build --context=deploy-preview
, then visit the site and inspect the value ofwindow.nextjsConfig
in the console, I see the value "local" I set for the dev context. Changing to different contexts has no effect. Prod deployments also carry thelocal
value.If I run
netlify build --context=deploy-preview
and then inspect the contents of the.next
folder, I can see that the correct values are being build into the compiled JS files. Unfortunately, if I then runnetlify deploy
, due to what I assume is an unrelated bug, the deployed site always shows a 404 error, I suspect because the netlify.toml file is being incorrectly deployed and the various Next.JS SSR redirect rules aren't being deployed - I haven't had a chance to fully investigate this yet.Configuration
Environment
The text was updated successfully, but these errors were encountered: