Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

500 error - is not a valid GTM-ID #38

Open
tebaly opened this issue Jul 28, 2024 · 0 comments
Open

500 error - is not a valid GTM-ID #38

tebaly opened this issue Jul 28, 2024 · 0 comments

Comments

@tebaly
Copy link

tebaly commented Jul 28, 2024

Only a specially-named environment variable can override a runtime config property. That is, an uppercase environment variable starting with NUXT_ which uses _ to separate keys and case changes.

First, you have to add a check to make sure that the secondary value exists at all.

const moduleOptions: ModuleOptions = defu(nuxt.options.runtimeConfig.public.gtm, options)

If you make a mistake in naming the ENV variable due to carelessness, the entire application will crash in production, but will work in any version locally.

This happens because there is a .env file locally. In production, .env is not recommended and you need to use environment variables.

Since your primary source of the value is the runtime config variables, the module settings are erased with an empty value from the runtime config. This is an error, since the environment variable should in principle be optional, and if it is present, the value of the module settings is replaced. And if there is no environment variable, the setting from the module configuration should be taken.


Nuxt has a very confusing system of ENV variables. When a variable is defined in the runtime config like this

  runtimeConfig: {
    public: {
      gtm: {
        id: process.env.GOOGLE_TAG_MANAGER_ID

Then the environment variable should be

NUXT_PUBLIC_GTM_ID=GTM-QWERTY0

A typo in the naming of an environment variable should not crash the production. Your module in its current form is dangerous :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant