我正在尝试将我的react-router-dom更新到v6,但它似乎会导致成帧器运动AnimatePresence出现问题,特别是退出过渡。
在 App.js 中:
import { Routes, Route } from "react-router-dom";
import {AnimatePresence} from "framer-motion";
import Home from "./Components/Home";
import About from "./Components/About";
function App() {
return (
<div className="App">
{/* globals such as header will go here */}
<AnimatePresence exitBeforeEnter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="about" element={<About />} />
</Routes>
</AnimatePresence>
</div>
);
}
export default App;
Run Code Online (Sandbox Code Playgroud)
然后在我的关于/主页组件中我有:
import {Link} from "react-router-dom";
import {motion} from "framer-motion";
function About() {
const pageMotion = {
initial: {opacity: 0, x: …Run Code Online (Sandbox Code Playgroud) javascript reactjs create-react-app react-router-dom framer-motion
我已经使用 Create React App 在 React 中创建了一个 Web 应用程序。在我的开发过程中,我的开发服务器的启动时间急剧增加。现在启动大约需要 8 分钟。我正在使用 Craco 修改我的 Webpack 配置并编译我的 Less 主题,但我可以确认,不使用 Craco 启动也需要同样的时间。当我使用 Craco 和 Webpackbar 运行我的服务器时,我可以看出大部分启动时间都是由 babel-loader 转译 node_modules 中的文件占用的,所以我怀疑这要么是我的配置或我的依赖项的问题。该项目是用 TypeScript 编写的,除了 React 之外,我最大的两个依赖项是 Ant Design (antd) 和 Ant Design Icons (@antd/icons)。
我已包含 package.json 和 craco.config.js 以及下面文件的依赖项以显示依赖项树:
//package.json
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"@ant-design/icons": "^4.7.0",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"antd": "^4.17.2",
"axios": "^0.23.0",
"craco-less": "^1.20.0",
"rc-footer": "^0.6.6",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^5.3.0",
"react-syntax-highlighter": "^15.4.4",
"web-vitals": "^1.1.2" …Run Code Online (Sandbox Code Playgroud) 昨天尝试使用 create-react-app 启动一个新的 React 应用程序。不幸的是,当我使用该命令时npx create-react-app my-app,它显示“创建 React App 需要 Node 14 或更高版本”。但是,当我尝试更新到 Node 14 或任何更高版本时,它说需要 Windows 8 或更高版本才能更新。由于我使用的是工作电脑,因此将我的计算机升级到 Windows 10 的过程很慢,并且可能会影响我计算机上的其他软件。
我一直在尝试理解 Webpack 和 Babel,但遇到了很多 create-react-app 不会出现的问题。有没有办法在Windows 7上使用create-react-app?
提前致谢。
我试图在使用 vscode 时禁用 eslint 对特定规则的保存修复。在实践中,我希望向用户显示 React hooks 的依赖项数组问题,但不修复。这是我的settings.json:
{
"editor.formatOnSave": false,
"[javascript]": {
"editor.formatOnSave": false
},
"[javascriptreact]": {
"editor.formatOnSave": false
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
},
"eslint.codeActionsOnSave.rules": [
"!react-hooks/exhaustive-deps",
"*"
],
"eslint.validate": ["javascript", "javascriptreact"]
}
Run Code Online (Sandbox Code Playgroud)
我希望 eslint 在我违反详尽的 deps 规则时显示警告,但在保存文件时将其保留在那里。相反,我的代码在保存时仍然固定,我做错了什么?
(注意:钩子依赖关系规则不应被破坏,但我正在处理一个现有的项目,我无法审查所有现有的钩子,并且我已经看到代码中断,因为钩子在不应该触发的情况下触发因为 ESLint 的自动修复)
javascript formatting eslint visual-studio-code create-react-app
我需要将React Codes Split与托管在 Firebase Hosting 上的 Create React App 结合使用。
但是,我有一个问题,因为Firebase Hosting 仅托管任何应用程序的最新版本。这意味着,如果您部署新的应用程序版本(N+1),并且用户打开现有版本(N),并且该用户跨越代码分割边界,他们将请求旧块(N),这不是不再在 Firebase 托管中托管,因为当前版本已更改 (N+1)。
那么,如何避免ChunkLoadErrorFirebase 托管中的代码拆分呢?有没有办法告诉 Firebase 托管保留您已部署的所有先前版本,并且仅添加最新版本中的新文件(例如index.htmlJS/CSS 块?)。
javascript reactjs google-cloud-platform firebase-hosting create-react-app
我正在使用 craco 创建一个反应应用程序。这是我的 ts 配置:
{
"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",
"downlevelIteration": true
},
"include": [
"src"
]
}
Run Code Online (Sandbox Code Playgroud)
我还使用 git 子模块从中导入 utils。
当我运行时craco start一切正常。但是当我运行时craco build我收到此错误:
Attempted import error: '@pinata/sdk' does not contain a default export (imported as 'pinataClient')
Run Code Online (Sandbox Code Playgroud)
这是pinataClient导入的方式:
import pinataClient "@pinata/sdk"; …Run Code Online (Sandbox Code Playgroud) 最近升级到了 React-scripts 版本 5.0.1,为此,我需要通过导入NodePolyfillPlugin我的 React-scripts 配置并将其添加到插件中来重新添加对 Node.js 核心模块的支持。这确实解决了我看到的错误,但现在我在尝试执行以下操作时遇到了一些新错误npm start:
Module not found: Error: You attempted to import /node_modules/console-browserify/index.js which falls outside of the project directory.
Run Code Online (Sandbox Code Playgroud)
对 console-browserify 的唯一引用来自 NodePolyfillPlugin。有谁知道为什么会发生这种情况以及我该如何解决它?
我有一个 React 应用程序,它使用以下命令从本地 json 文件加载数据
从“./data.json”导入数据
一切工作正常,没有任何问题,我可以在 3000 中打开我的 index.html,也可以在浏览器中将其作为简单的 HTML 页面打开。
现在我运行npm run build来创建构建目录。然而,我的 json 值变得有点停滞,因为它是在构建中的 javascript 中硬编码的。所以问题是我在 build 目录中的代码如何动态地从特定位置读取 json 文件。
我遇到了一个问题并发现它是因为 Babel 没有.at默认填充
根据spec,Array.prototype.at只是第4阶段,我已经将browserslist设置为> 0.2%,其中包括Chrome 86(尚不支持.at)
为什么 Babel 不使用 polyfill .at 呢?
我正在尝试关注从react-create-app添加env变量的文档,但没有成功:
这是app.js,我试图访问process.env但没有成功.
我无法在代码中访问process.env.有关于如何做到这一点的工作实例吗?
create-react-app ×10
reactjs ×7
javascript ×5
craco ×2
node.js ×2
antd ×1
babel-loader ×1
babeljs ×1
build ×1
core-js ×1
eslint ×1
formatting ×1
polyfills ×1
typescript ×1
webpack ×1