FE7: The modern frontend toolkit

Lesson 5 of 5 ยท reading 15โ€“25 minutes; practice and project time is on the module page

Environments, configuration and error monitoring

๐ŸŽฏYou'll be able to

Keep secrets out of the browser and set up error monitoring.

๐Ÿ The everyday picture

A theatre rehearses on a practice stage before opening night, and keeps an usher watching the audience during the show. Separate environments are the practice stage; error monitoring is the usher.

๐Ÿ“˜What it really is

๐Ÿ“A worked example

Kirana Express configuration:

Variable Development Preview Production
VITE_API_URL localhost:4000 api-staging.kirana.example api.kirana.example
VITE_PAYMENT_MODE test test live
VITE_SENTRY_ENV (off) preview production

A week after release 3.4, error monitoring showed a new error, "Cannot read properties of undefined (reading 'slots')", from 2% of checkout visits, all on stores with no delivery slots that day. The source map pointed to the exact line, and a fix shipped the same afternoon.

๐ŸŒWhere it's used

๐Ÿ“Case scenario

A developer commits a .env file containing a third-party API key, and the repository is public. Even after deleting the file, the key is in Git history. You rotate the key with the provider, add .env to .gitignore, commit .env.example instead, and turn on secret scanning for the repository.

๐Ÿ–ฑ๏ธTry it

Set up development and preview configurations for your Kirana app with an .env.example. Add an error monitoring tool (a free tier is enough), trigger a deliberate error, and check that the report shows the source file and line.

โš ๏ธCommon mistakes

๐Ÿ› ๏ธFor your project

The kit's .env.example holds only practice values. The project pages refuse text that looks like a real secret.

โœ…Quick check

Which Vite environment variables reach browser code?

Show the answer

Those starting with VITE_, which means they must never hold secrets.

What do source maps do?

Show the answer

They map minified production code back to the original source, so errors can be traced to the right line.

โ† PreviousLinting, formatting and code checks
ProLearners Assist