使用create-react-app出现Uncaught ReferenceError: process is not defined及代码修改后iframe阻塞应用问题求助
process is not defined Error in React Projects Hey there, sorry to hear you're stuck with this frustrating issue—nothing kills productivity faster than your app locking up with random iframes and cryptic console errors! Let’s walk through potential fixes step by step:
1. Rule Out Browser Extensions or External Injection
That fixed-position iframe screams "external interference" first. Try these quick checks:
- Disable all browser extensions (especially ad blockers, developer tools add-ons, or VPN-related extensions) and reload your app.
- Open your app in incognito/private browsing mode—this automatically disables most extensions, so if the issue disappears, you know an extension is the culprit.
2. Resolve the process is not defined Error
This error is likely the root cause of your app blocking, and it’s common with newer React Scripts versions (Webpack 5 removed automatic injection of process variables). Here’s how to fix it without ejecting:
Option A: Use Environment Variables File
Create a .env file in your project root directory and add this line:
NODE_ENV=development
Restart your dev server afterward—this should expose the basic process env variables your app needs.
Option B: Override Webpack Config with react-app-rewired
If the .env fix doesn’t work, use react-app-rewired to tweak the Webpack config safely:
- Install the package:
npm install react-app-rewired --save-dev - Create a
config-overrides.jsfile in your project root with this code:const webpack = require('webpack'); module.exports = function override(config) { config.plugins.push( new webpack.DefinePlugin({ 'process.env': JSON.stringify(process.env) }) ); return config; }; - Update your
package.jsonscripts to usereact-app-rewiredinstead ofreact-scripts:"scripts": { "start": "react-app-rewired start", "build": "react-app-rewired build", "test": "react-app-rewired test", "eject": "react-scripts eject" } - Restart your dev server.
3. Clean Caches and Reinstall Dependencies
Corrupted cache or dependency files can cause weird behavior. Run these commands:
- Clear npm cache:
npm cache clean --force - Delete
node_modules,package-lock.json(oryarn.lock), then reinstall:rm -rf node_modules package-lock.json npm install - Start the dev server with no cache:
npm start -- --no-cache
4. Audit Your Code and Dependencies
- Search your codebase for any direct use of
process—if you’re using it in your own code, replace it with the appropriate React environment variable (e.g.,process.env.REACT_APP_YOUR_VARfor custom variables). - Check your dependency tree for packages that might rely on
processwithout handling Webpack 5 changes. Usenpm lsto list all dependencies, and look for outdated packages that might need updates.
5. Investigate the Persistent iframe
If the iframe still appears after fixing the process error:
- Check your
public/index.htmlfile to ensure no unauthorized code was added there. - Use
npm lsoryarn whyto look for any suspicious dependencies that might inject iframes (rare, but possible with malicious or poorly maintained packages).
内容的提问来源于stack exchange,提问作者Youssef B

