我正在尝试创建反应应用程序的所有方法.我尝试过使用maven,现在我正在尝试使用Facebook Incubators的crate-react-app构建系统.
当我试图create-react-app my-app在npm环境中运行命令时,它在我的个人系统上运行没有问题.但是当我在我的工作环境中尝试相同的命令时,我在命令提示符下遇到了这个错误
npm ERR! node v6.10.2
npm ERR! npm v3.10.10
npm ERR! code UNABLE_TO_GET_ISSUER_CERT_LOCALLY
npm ERR! unable to get local issuer certificate
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
Run Code Online (Sandbox Code Playgroud) 我一直在Internet Explorer上测试我的React.js应用程序,令我惊讶的是,ES6代码就像Array.prototype.includes()打破它一样.我正在使用creat-react-app入门套件,我认为babel是其中的一部分,并且它允许我编写ES6代码.
事实证明它并不那么简单.从我所看到的,他们选择不包括大量的polyfill,因为不是每个人都需要它,并且它减慢了构建时间.例如,在此处和此处查看.有人试图记录这一点,但没有提到如何自己实际进行填充.只是这个:
如果您使用任何其他需要运行时支持的ES6 +功能(例如Array.from()或Symbol),请确保手动包含相应的polyfill,或者您所定位的浏览器已经支持它们.
那么......"手动"包含它们的最佳方式是什么?我认为那是babel用于什么的一部分?我应该部分导入babel-polyfill的元素吗?
什么是npm run eject命令吗?我确实理解其他命令的作用,如启动,构建,测试.但不知道弹出.
我正在努力解决 VSCode 中的“错误”:
Argument for '--jsx' option must be: 'preserve', 'react-native', 'react'
Run Code Online (Sandbox Code Playgroud)
因此,当value 似乎有效时,react-scripts (create-react-app) 会自动将jsxkey设置为react-jsxvalue react。
实际上,代码运行良好并显示了我想要的页面,但是 IDE 将所有内容都强调为错误,并说:
Cannot use JSX unless the '--jsx' flag is provided.
Run Code Online (Sandbox Code Playgroud)
这是我的 tsconfig.json :
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
} …Run Code Online (Sandbox Code Playgroud) 当我运行 时npx create-react-app ...,正在为我创建一个简单的 React 项目。然后当我查看 时package.json,似乎有一些 ESLint 存在的证据,因为有这样的:
"eslintConfig": {
"extends": "react-app"
},
Run Code Online (Sandbox Code Playgroud)
然而,每当我将 ESLint 作为开发依赖项安装并配置它时——就像我通常所做的那样——,VS Code 似乎会选择它。在这种情况下,VS Code 似乎没有意识到存在/配置了任何类型的 linter。这并不奇怪,因为 ESLint 不是我刚刚生成的 React 项目的依赖项——至少不是根据package.json. 当我尝试eslint .在项目的根目录中运行时,它显示“找不到命令”。
我试图通过扩展它来为这个 ESLint 配置注入活力,所以现在我有了:
"eslintConfig": {
"extends": ["react-app", "eslint:recommended", "google"],
"rules": {
"semi": ["error", "always"],
"quotes": ["error", "double"]
}
},
Run Code Online (Sandbox Code Playgroud)
这没有任何改变。我以一种我知道它违反上述配置的方式操作源代码,但是,我没有收到任何不法行为的信号。
这让我想到一个简单的问题:
生成的项目是否create-react-app带有某种 ESLint 配置,如果是,我该如何正确启用和扩展它?
当我提到在搜索“create react app eslint”时出现的排名第一的谷歌点击- 我显然已经阅读过 - 让我澄清我的意思:
ESLint 显然是以一种不同的方式集成到 Create React App 中,而不是像这样 …
javascript reactjs eslint visual-studio-code create-react-app
即使在完成卸载部分之后,我还是一次又一次地收到此 create React app 错误。
npm uninstall -g create-react-app
最新,在 570 毫秒内审核了 1 个包
发现0个漏洞
npx create-react-app test-app
需要安装以下软件包: create-react-app 确定继续吗?(y) y
您正在运行
create-react-app4.0.3,它落后于最新版本 (5.0.0)。我们不再支持 Create React App 的全局安装。
请使用以下命令之一删除所有全局安装:
- npm uninstall -g 创建-react-app
- 纱线全局删除create-react-app
创建新应用程序的最新说明可以在这里找到: https ://create-react-app.dev/docs/getting-started/
C:\>npm --version
8.3.0
C:\>node --version
v16.13.0
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
更新到 CRA 5.0.0 后,我在编译过程中遇到此错误:
\nERROR in Plugin "react" was conflicted between ".eslintrc.json" and "BaseConfig \xc2\xbb "..\\react-app\\node_modules\\eslint-config-react-app\\base.js".\nRun Code Online (Sandbox Code Playgroud)\n我的 eslint 配置是:
\n{\n "env": {\n "browser": true,\n "es2021": true\n },\n "extends": [\n "plugin:react/recommended",\n "airbnb",\n "plugin:react/jsx-runtime"\n ],\n "parser": "@typescript-eslint/parser",\n "parserOptions": {\n "ecmaFeatures": {\n "jsx": true\n },\n "ecmaVersion": 12,\n "sourceType": "module"\n },\n "plugins": [\n "react",\n "@typescript-eslint"\n ],\n "rules": {...}\n}\nRun Code Online (Sandbox Code Playgroud)\n有任何解决方案/修复吗?
\n我尝试create-react-app使用npm i create-react-app,npx create-react-app new-app和安装npm init react-app new-app,但我不断收到此错误消息:
You are running create-react-app 4.0.0, which is behind the latest release (4.0.1).
We no longer support global installation of Create React App.
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
我有一个项目,我没有触摸2周.我收回它,现在当我尝试运行时,npm start我收到了这个错误.
> react-scripts start
sh: react-scripts: command not found
npm ERR! Darwin 16.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v6.7.0
npm ERR! npm v3.10.3
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! UpScore@0.6.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the UpScore@0.6.0 start script 'react-scripts start'.
npm ERR! Make sure you have the latest version of node.js and …Run Code Online (Sandbox Code Playgroud) 使用React 16.8.6(在以前的版本16.8.3中很好),当我尝试防止在获取请求上发生无限循环时,出现此错误
./src/components/BusinessesList.js
Line 51: React Hook useEffect has a missing dependency: 'fetchBusinesses'.
Either include it or remove the dependency array react-hooks/exhaustive-deps
Run Code Online (Sandbox Code Playgroud)
我一直找不到停止无限循环的解决方案。我想远离使用useReducer()。我确实在https://github.com/facebook/react/issues/14920找到了这个讨论,在这里可能的解决方案是You can always // eslint-disable-next-line react-hooks/exhaustive-deps if you think you know what you're doing.我不确定自己在做什么,所以我还没有尝试实现它。
我有这个当前设置,React hook useEffect永远/无限循环连续运行,唯一的注释是useCallback()我不熟悉的。
我目前的使用方式useEffect()(类似于,我一开始只想运行一次componentDidMount())
useEffect(() => {
fetchBusinesses();
}, []);
Run Code Online (Sandbox Code Playgroud)
const fetchBusinesses = () => {
return fetch("theURL", {method: "GET"}
)
.then(res => normalizeResponseErrors(res))
.then(res => {
return res.json();
}) …Run Code Online (Sandbox Code Playgroud) create-react-app ×10
reactjs ×9
eslint ×3
npm ×3
javascript ×2
npx ×2
babeljs ×1
ecmascript-6 ×1
jsx ×1
node.js ×1
npm-install ×1
package ×1
react-hooks ×1
tsconfig ×1
typescript ×1
webpack ×1