You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除React应用中未随Shell会话失效的临时环境变量?

How to Remove the Lingering Temporary Environment Variable for Create React App

Hey there! Let's tackle this issue where your REACT_APP_NOT_SECRET_CODE environment variable is sticking around even after you restart npm start. Here's what's going on and how to fix it:

Why is the variable still there?

When you ran ($env:REACT_APP_NOT_SECRET_CODE = "abcdef") -and (npm start) in PowerShell, you set the variable only for the current Shell session. If you didn't close that PowerShell window and just ran npm start again, the variable is still present in the active session—that's why Create React App keeps picking it up.

Step-by-Step Fixes

  1. Remove the variable from your current PowerShell session
    Run this command to delete the environment variable immediately in your open Shell:

    Remove-Item Env:REACT_APP_NOT_SECRET_CODE
    

    You can verify it's gone by running:

    echo $env:REACT_APP_NOT_SECRET_CODE
    

    If this returns nothing, the variable is removed. Now restart npm start and it won't see the variable anymore.

  2. Kill leftover Node.js processes (if needed)
    Sometimes, npm might leave background processes running that still hold onto the environment variable. To clear these out:

    Stop-Process -Name node -Force
    

    Note: This will terminate all running Node.js processes on your machine, so save any unsaved work in other Node apps first!

  3. Check for accidental permanent setup
    If the variable keeps coming back even after closing and reopening PowerShell, double-check if you accidentally added it to your PowerShell profile. Open your profile file with:

    notepad $PROFILE
    

    Look for any lines setting REACT_APP_NOT_SECRET_CODE—delete them if found, save the file, and restart PowerShell.

That should take care of the lingering variable!

内容的提问来源于stack exchange,提问作者suhaas.dev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 14:57:44