VSCODE not recognizing .env* files for markup porpuses and not recognizing .env.local.* files

Viewed 3276

Environment:

NextJs, React, VsCode

  1. Syntax highlights not being recognized by VSCODE.

I have installed the following extensions:

Have done the followin on my json config file:

"files.associations": {
            "*.js": "javascriptreact",
            "*.env.development": "env",
            "*.env.production": "env",
            "*.env.local": "env",
    },
  1. VsCode should recognize .env naming as per the file I have created:

.env.local.example

I have tested a public variable NEXT_PUBLIC_ENV_LOCAL_VARIABLE = "Some public stuff" and it does not work when I test it on the browser. When I add the termination .example to .env.local file, Vscode stops recognizing the file at all.

Thanks for the help

2 Answers

Your configs glob patterns seem to be the problem.

*.env.local covers example.env.local and not .env.local.example. If you append identifiers to the end of the filename your config should be like this:

"files.associations": {
            "*.js": "javascriptreact",
            ".env.development.*": "env",
            ".env.production.*": "env",
            ".env.local.*": "env",
    },

Or even this would be sufficient I think:

"files.associations": {
            "*.js": "javascriptreact",
            ".env.*": "env",
    },
Related