Category: Vercel and hosting

The environmental variable works locally and on Vercel does not

Read this guide in Polish

Local env file is not automatically a production configuration. Vercel distributes the environment, and some of Next.js variables go into the code as they build.

Step by step

1. Check the name of the variable in the code and the failed implementation environment: Production or Preview. Open project settings and compare assigning a variable without copying a secret to report.

2 . Determine whether the value is to be read on the server or in the browser. The NEXT PUBLIC prefix means the public value attached to the client code; do not use it for server APIs.

3 . After changing configuration, create a new implementation with the right commit. The old build may still contain the previous public value.

4 . If an error occurs, log in the information about the existence of the configuration and not its content. Also check the spaces and characters of the new line if the provider rejects the correctly named variable.

5 . Compare your own domain with the implementation address. Make sure you test the design and environment in which the settings have just been changed.

How to check whether the amendment works

The new implementation should perform the test operation without revealing the secret in the page code. If the key came to the client earlier, remove it from the code and invalidate it from the supplier.