- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经在这个问题上花了几天时间。是的,我升级到 react-scripts 5,是的,我把 "react-error-overlay": "6.0.9" 放在 package.json 里,是的,我 < strong>删除了 node-modules + package-lock.json,清除了缓存并重新安装了 npm。
在我完成所有这些之后,错误变得更糟。在错误发生之前让我使用该应用程序一段时间并使一切都无响应,我现在在启动该应用程序时立即看到一个白屏并立即发生此错误。
此外,为什么使用“process?.env”而不是“process.env”不能解决代码层面的问题?
错误:
`Uncaught ReferenceError: process is not defined
at ./src/GlobalProperties.ts (GlobalProperties.ts:18:1)
at options.factory (react refresh:6:1)
at __webpack_require__ (bootstrap:24:1)
at fn (hot module replacement:62:1)
at ./src/pages/LoginPage.tsx (ForgotPasswordPage.tsx:75:1)
at options.factory (react refresh:6:1)
at __webpack_require__ (bootstrap:24:1)
at fn (hot module replacement:62:1)
at ./src/error/pages/NotFoundPage.tsx (ForbiddenPage.tsx:34:1)
at options.factory (react refresh:6:1)`
引发错误的代码行:
environment: process !== undefined ? (process.env?.REACT_APP_ENV || "DEV") : "DEV",
(试过只做过程?.env?,同样的事情)
我的 package.json:
{
"name": "my_app_name",
"version": "0.0.1",
"private": true,
"dependencies": {
"@capacitor/app": "1.1.1",
"@capacitor/core": "3.5.1",
"@capacitor/haptics": "1.1.4",
"@capacitor/keyboard": "1.2.2",
"@capacitor/status-bar": "1.0.8",
"@ionic/react": "^6.0.3",
"@ionic/react-router": "^6.0.3",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^14.2.0",
"@types/date-fns": "^2.6.0",
"@types/jest": "^28.1.1",
"@types/node": "^17.0.41",
"@types/qs": "^6.9.7",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react-router": "^5.1.18",
"@types/react-router-dom": "^5.3.3",
"@types/validator": "^13.7.1",
"date-fns": "^2.28.0",
"ionicons": "^6.0.2",
"moment": "^2.29.1",
"print-js": "^1.6.0",
"react": "^17.0.0",
"react-acceptjs": "^0.2.0",
"react-device-detect": "^2.2.2",
"react-dom": "^17.0.2",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "^5.0.0",
"typescript": "^4.5.5",
"validator": "^13.7.0",
"web-vitals": "^2.1.4",
"workbox-background-sync": "^6.5.3",
"workbox-broadcast-update": "^6.5.3",
"workbox-cacheable-response": "^6.5.3",
"workbox-core": "^6.5.3",
"workbox-expiration": "^6.5.3",
"workbox-google-analytics": "^6.5.3",
"workbox-navigation-preload": "^6.5.3",
"workbox-precaching": "^6.5.3",
"workbox-range-requests": "^6.5.3",
"workbox-routing": "^6.5.3",
"workbox-strategies": "^6.5.3",
"workbox-streams": "^6.5.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --transformIgnorePatterns 'node_modules/(?!(@ionic/react|@ionic/react-router|@ionic/core|@stencil/core|ionicons)/)'",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"resolutions": {
"react-error-overlay": "6.0.9"
},
"devDependencies": {
"@capacitor/cli": "3.5.1",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"react-error-overlay": "^6.0.9"
},
"description": "An Ionic project"
}
这是发生错误的完整文件:
/**
README
To change the title of the app (in the title bar of browser), edit /public/index.html
For app name in the app or android store, edit ionic.config.json "name" attr.
*/
import { StateType } from './javatoreact/Types';
// const process : any = process || {};
const GlobalProperties = {
averageDebounceTime: 500,
environment: process !== undefined ? (process.env?.REACT_APP_ENV || "DEV") : "DEV",
};
const DEFAULT_DEV_API = "CENSORED";
// this is a separate const to make sure it can't be changed at runtime
export const ENVIRONMENT_WEB_SERVICE_URL = process?.env?.REACT_APP_API || DEFAULT_DEV_API;
export const getColorByStatus = (status?: StateType) => {
let color = "medium";
switch(status) {
case StateType.SCHEDULED:
color = "primary";
break;
case StateType.COMPLETED:
color = "success";
break;
case StateType.REJECTED:
color = "danger";
break;
case StateType.CANCELLED:
case StateType.POSTPONED:
color = "warning";
break;
}
return color;
}// end getColorByStatus
export default GlobalProperties;
最佳答案
process
在浏览器上不存在,但是 process.env.NODE_ENV
在构建时是硬编码的,其他以 开头的环境变量也是如此REACT_APP
如果您添加了它们。
所以也许创建一个像这样的辅助方法:
export const isDev = () => {
try {
return process.env.NODE_ENV === "development";
} catch {
return false;
}
};
关于reactjs - Uncaught ReferenceError : process is not defined (yes I tried all the solutions internet says should solve this),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72634921/
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 5年前关闭。 Improve t
我是一名设计老师,试图帮助学生应对编程挑战,所以我编码是为了好玩,但我不是专家。 她需要找到 mode (最常见的值)在使用耦合到 Arduino 的传感器的数据构建的数据集中,然后根据结果激活一些功
我正在开发一个应用程序,该应用程序提供 CPU 使用率最高的 5 个应用程序名称。目前,我通过以下代码获得了排名前 5 的应用程序: var _ = require('lodash');
互联网上很少有例子涉及这个问题的所有三个问题——即 set-process-sentinel ; set-process-filter ;和 start-process . 我尝试了几种不同的方法来微
如 this post 中所述,在 C# 中有两种调用另一个进程的方法。 Process.Start("hello"); 和 Process p = new Process(); p.StartInf
我试图让我的桨从白色变为渐变(线性),并使球具有径向渐变。感谢您的帮助!您可以在 void drawPaddle 中找到桨的代码。 这是我的目标: 这是我的代码: //球 int ballX = 50
考虑:流程(a)根据我的文字: A process is first entered at the time of simulation, at which time it is executed u
我真的希望 Processing 有用于处理数组的 push 和 pop 方法,但由于它没有,我不得不试图找出删除数组中特定位置的对象的最佳方法。我相信这对很多人来说都是基本的,但我可以使用一些帮助,
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
以编程方式,我如何确定 Windows 10 中的 3 个类别 应用 后台进程 Windows 服务 就像任务管理器一样? 即我需要一些 C# 代码,我可以确定应用程序列表与后台进程列表。检查 Win
当我导入 node:process它工作正常。但是,当我尝试要求相同时,它会出错。 这工作正常: import process from 'node:process'; 但是当我尝试要求相同时,它会引
我正在上一门使用处理的类(class)。 我在理解 map() 函数时遇到问题。 根据它的文档( http://www.processing.org/reference/map_.html ): Re
我试图执行: composer.phar update 并收到: Fatal error: Allowed memory size of 94371840 bytes exhausted (tried
给定一堆二维图像,如何使用 Processing/Processing.js 产生体积渲染效果? 目前我的想法是使用 java(类似于 imageJ)进行体积渲染 -> 获取体积渲染图像的面作为单独的
这是代码示例 var startInfo = new ProcessStartInfo { Arguments = commandStr, FileName = @"C:\Window
当我在 Processing(草图 > 导入库 > 添加库)中添加库时,它安装在哪里? 最佳答案 它们安装在您的 中速写本位置 . 您可以通过转到"file">“首选项”来查看和更改您的速写本位置。草
无聊的好奇... 我正在查看当前进程的一些属性: using(Process p = Process.GetCurrentProcess()) { // Inspect properties
我正在尝试在同一页面上运行多个草图。 初始化脚本指定: /* * This code searches for all the * in your page and loads each scrip
Process.Kill 后是否需要使用 Process.WaitForExit? 如果调用进程在调用 Process.Kill 后立即退出怎么办? 这会导致 Process.Kill 失败吗? 编辑
我尝试使用处理从麦克风获取频率。我混合了文档中的两个示例,但“最高”并不是真正的赫兹(a 是 440 赫兹)。 你知道如何拥有比这更好的东西吗? import ddf.minim.*; import
我是一名优秀的程序员,十分优秀!