我console.log()在开发应用程序时使用了很多语句(我的意思是LOTS)。在没有Create React App 的情况下"ejecting",
我究竟如何才能删除它们
我考虑过但不确定如何实现:
在我的 package.json 中:
"build": "react-scripts build && uglifyjs --compress drop_console build/static/js/main.xxxxx.js -o build/static/js/main.xxxxx.js
Run Code Online (Sandbox Code Playgroud)
但是,我究竟如何知道文件的hash后缀,main.js以便我可以调用此命令并使用相同的文件名保存输出 js 文件
构建后我想要一个根文件夹中的配置文件(JSON)来配置我的应用程序。
像Translation和API Urls和...
我可以使用 create react app 来做到这一点吗?
我试图弄清楚如何使用不同的配置文件运行反应应用程序(通过create-react-app 创建)。
也就是说,假设我有多个环境(本地、开发、生产)并且我有一个指向后端(部署在另一台服务器上)的提取。
后端对每个环境都有自己的地址。我需要以某种方式为不同的发布设置全局变量。
例如,在 Springboot 中,这可以通过 application-"profile".properties 完成。
我通过 npm install -g serve & serve -s build 运行应用程序。怎么做?
我不知道如何在玩笑中模拟内部函数的返回值我尝试了不同的方法。最后我找到了这个答案, 但由于某种原因不值得嘲笑,这是示例:
国家.js
export const countryList = () => [
{
label: '+244',
value: 'Angola',
}, // list of all possible countries very long...
];
export const getSortedCountryData = intlLang =>
countriesList()
.sort((compare, comparable) =>
compare.value.localeCompare(comparable.value, intlLang, { sensitivity: 'base' }));
Run Code Online (Sandbox Code Playgroud)
国家.test.js
import * as countyListHelper from './countries';
describe('countries list', () => {
test('returns list of countries', () => {
const mockFn = jest.mock();
const expectedList = [
{
label: '+244',
value: 'Angola',
},
{
label: '+43',
value: 'Austria', …Run Code Online (Sandbox Code Playgroud) 我正在开发一个使用 create-react-app 引导的 React 应用程序,它在 Chrome 中运行良好,但我无法让它在 IE11 中运行。
启动应用程序后,我从控制台收到以下错误:
Object doesn't support property or method 'entries'
我花了好几个小时在谷歌上搜索,试图找到一个解决方案,但没有一个推荐的方法有效。
我尝试过的事情:
react-app-polyfill/ie11和react-app-polyfill/stable在顶部index.jscore-js/es/object/entries和core-js/features/object/entries在顶部index.jsindex.js:if (!Object.entries) {
Object.entries = function( obj ){
var ownProps = Object.keys( obj ),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array
while (i--)
resArray[i] = [ownProps[i], obj[ownProps[i]]];
return resArray;
};
}
Run Code Online (Sandbox Code Playgroud)
包.json:
{
"name": "ceas-ui",
"version": "0.1.0",
"private": true,
"dependencies": {
"auth0-js": …Run Code Online (Sandbox Code Playgroud) 我和我的团队使用 create-react-app bootstrap 命令启动一个新的 React 项目。我们在项目中添加了 eslint 部分,但我们遇到了以前从未发现过的恼人错误。当我们启动命令时
yarn run lint
Run Code Online (Sandbox Code Playgroud)
这里是 package.json:
{
"name": "name of the app",
"version": "0.1.0",
"private": true,
"dependencies": {
"jwt-decode": "^2.2.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-intl": "^3.12.0",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"react-scripts": "3.3.0",
"redux": "^4.0.5",
"redux-saga": "^1.1.3",
"reselect": "^4.0.0",
"styled-components": "^5.0.1"
},
"scripts": {
"analyze": "react-app-rewired build",
"build": "react-scripts build",
"cypress": "./node_modules/.bin/cypress open",
"eject": "react-scripts eject",
"lint:write": "eslint --debug src/ --fix",
"lint": "eslint --debug src/",
"prettier": "prettier --write src/*.tsx src/*.ts src/**/*.tsx src/**/*.ts src/**/**/*.tsx …Run Code Online (Sandbox Code Playgroud) 该ReactJS文档中阐明的我们可以使用
npx create-react-app my-app
Run Code Online (Sandbox Code Playgroud)
创建一个 React 应用程序。但是我们如何更新create-react-app?如果它是由 开始的,是否有一般规则npx?我继续点击一些链接并到达网站https://create-react-app.dev/并且它有一行:
npm install react-scripts@latest
Run Code Online (Sandbox Code Playgroud)
但我想知道我是否运行它,它不是-g(全局),所以它可以让我们在任何文件夹中创建一个 React 应用程序吗?此外,当我运行它时,它给出了:
found 6289 vulnerabilities (4974 low, 306 moderate, 1004 high, 5 critical)
Run Code Online (Sandbox Code Playgroud)
所以似乎有一些需要额外做的事情。
我有一个带有 ReactJS 的 ASP.NET 6 应用程序,是前段时间使用 Visual Studio 2022ASP.NET Core with React.js模板创建的。
ClientApp 是一个使用create-react-app.
我已将我的react-scripts包更新到版本 5.0.0(从 4.0.3)。AFAIK 的重大变化之一是它现在使用 webpack 5。
自此更新以来,当我启动 ASP.NET 应用程序(使用同时启动 ASP.NET 应用程序和 React 应用程序的标准运行配置)时,只要我在任何 React 文件中进行更改,热重新加载就不会自动刷新浏览器。如果我手动点击浏览器的刷新按钮或 F5,我可以看到更改。唯一的变化是,在 React 文件发生更改后,浏览器不会自行刷新。
我使用的是 Windows 11。
这是我目前的package.json:
{
"name": "my.app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@types/jest": "^27.0.3",
"@types/node": "^16.11.9",
"@types/react": "^17.0.35",
"@types/react-dom": "^17.0.11",
"@types/react-router-bootstrap": "^0.24.5",
"bootstrap": "^5.1.3",
"jquery": "^3.5.1",
"merge": "^1.2.1",
"node-sass-chokidar": "^1.5.0",
"npm-run-all": "^4.1.5",
"oidc-client": "^1.9.0",
"react": "^16.0.0",
"react-bootstrap": …Run Code Online (Sandbox Code Playgroud) 我使用创建了一个新的反应项目npx create-react-app app-name --template typescript,它运行良好,直到我导入另一个.tsx文件。现在,当我尝试导入另一个.tsx文件时,出现错误:Module not found: Error: Can't resolve './components/component' in '/Users/benbaldwin/Desktop/project/frontend/teacher/src'
我做的唯一与平常不同的是文件结构。由于我的文件夹中有多个frontend共享依赖项的反应项目,因此我将 移动到node_modules覆盖所有这些子目录。我的文件结构如下所示:
- frontend
- node_modules
- project-1
- public
- src
index.tsx
react-app-env.d.ts
- components
component.tsx
- project-2
package.json
tsconfig.json
Run Code Online (Sandbox Code Playgroud)
组件文件如下所示:
- frontend
- node_modules
- project-1
- public
- src
index.tsx
react-app-env.d.ts
- components
component.tsx
- project-2
package.json
tsconfig.json
Run Code Online (Sandbox Code Playgroud)
索引文件如下所示:
import React from 'react';
const Component: React.FC = () => {
return <div>hello</div>;
}; …Run Code Online (Sandbox Code Playgroud) 每次当我运行任何 npx 命令时,它都会给我同样的错误。除非我运行:npx -v然后它给我版本:9.2.0
这是错误:
npm ERR! code ENOENT
npm ERR! syscall lstat
npm ERR! path E:\Development
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, lstat 'E:\Development'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Tim\AppData\Local\npm-cache\_logs\2023-01-02T20_03_57_627Z-debug-0.log
Run Code Online (Sandbox Code Playgroud)
我已经用 nvm 更新了 npm,但这并没有改变。
我想运行npx create-react-app myAppornpx create-electron-app myApp但每个命令都会给我同样的错误。有人可以帮助我消除这个错误吗?
create-react-app ×10
reactjs ×7
javascript ×3
typescript ×2
webpack ×2
asp.net-core ×1
core-js ×1
eslint ×1
jestjs ×1
npm ×1
npx ×1
uglifyjs ×1