Search code examples
typescriptvue.jswebpack

Vue Uncaught ReferenceError: process is not defined


I'm working on a Vue + typescript project. I want to use process.env.var_name to adjust the project is in development mode or production mode, just like

const isProduct = process.env.APP_ENV === "prod";

; however I got an error below. I never meet this error before, so could any one give me a clue why this would happen so I can try to figure out what happend in the project and then fix it.enter image description here


Solution

  • If you are using Vite, use import.meta.env instead, process.env is removed.

    And make sure variables start with VITE_ in .env file.

    VITE_SOME_KEY=123
    

    more https://vitejs.dev/guide/env-and-mode.html