标签: create-react-app

为什么 React 开发的 .env 文件中需要 REACT_APP 前缀?

https://create-react-app.dev/docs/adding-custom-environment-variables/中有一个声明 :

除 NODE_ENV 之外的任何其他变量都将被忽略,以避免意外暴露机器上可能具有相同名称的私钥。

在机器上公开可能具有相同名称的私钥是什么意思?我从这句话中什么也得不到。您能举例解释一下这个说法吗?先感谢您。

reactjs create-react-app dotenv

4
推荐指数
1
解决办法
4768
查看次数

使用 pnpm 安装 create React 应用程序显示警告

使用pnpm dlx和为 create-react 应用程序(版本 5.0.0)安装依赖项时pnpm import,我收到一条警告,提示应安装对等依赖项。React 的开发环境运行得很好。使用时不会出现此警告消息npx。除了安装对等依赖项之外,如何修复此警告消息?提前致谢。

\n

我做了什么:

\n
    \n
  1. 在命令行中使用 pnpm dlx 创建 React 应用程序
  2. \n
\n
pnpm dlx create-react-app ./temp-app\n
Run Code Online (Sandbox Code Playgroud)\n
    \n
  1. 上面的步骤创建了一个 package-lock.json 文件。因此,要创建 pnpm 的锁定文件,
  2. \n
\n
pnpm import package-lock.json\n
Run Code Online (Sandbox Code Playgroud)\n
    \n
  1. 这创建了一个 pnpm-lock.yaml 文件,其中包含如下警告消息
  2. \n
\n
\xe2\x80\x89WARN\xe2\x80\x89 Issues with peer dependencies found\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\xac @testing-library/user-event\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 \xe2\x9c\x95 missing peer @testing-library/dom@>=7.21.4\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\xac react-scripts\n  \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 \xe2\x9c\x95 missing peer typescript@"^3.2.1 || ^4"\n  \xe2\x94\x9c\xe2\x94\x80\xe2\x94\xac eslint-config-react-app\n  \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\xac @typescript-eslint/eslint-plugin\n  \xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 \xe2\x9c\x95 missing peer typescript@"*"\n …
Run Code Online (Sandbox Code Playgroud)

create-react-app pnpm

4
推荐指数
1
解决办法
5209
查看次数

Emotion 的 CSS 属性无法与 Create-React-App 一起使用

我想将 Emotion 与 CRA 一起使用,因此我按照文档安装了它,并尝试使用 css prop,如下例所示:

import { FC } from "react";
import { TypographyProps } from "./Typography.propTypes";
import * as styles from "./Typography.styles";

export const Typography: FC<TypographyProps> = ({
  children,
}) => {
  return <h1 css={styles.typography}>{children}</h1>;
};
Run Code Online (Sandbox Code Playgroud)

但没有成功。

通过检查代码,我发现了这一点:

<h1 css="You have tried to stringify object returned from `css` function. 
It isn't supposed to be used directly (e.g. as value of the `className` prop), 
but rather handed to emotion so it can handle it (e.g. as value of …
Run Code Online (Sandbox Code Playgroud)

css emotion reactjs create-react-app

4
推荐指数
1
解决办法
2724
查看次数

我无法修改create-react-app中的webpack.config来安装react-pdf

帮助我在创建react应用程序时安装react-pdf包(https://github.com/diegomura/react-pdf)。我无法更改 webpack.config。我按照用户 River Twilight 在这里找到的说明来执行此操作:How to update webpack config for a React Project Created using create-react-app?

根据安装react-pdf的说明

  1. 我跑npm install process browserify-zlib stream-browserify util buffer assert
  2. config-override.js在项目根文件夹中创建
  3. 接下来,您需要将以下行插入到配置中:

const webpack = require("webpack");

module.exports = {
  /* ... */

  resolve: {
    fallback: {
      process: require.resolve("process/browser"),
      zlib: require.resolve("browserify-zlib"),
      stream: require.resolve("stream-browserify"),
      util: require.resolve("util"),
      buffer: require.resolve("buffer"),
      asset: require.resolve("assert"),
    }
  },
  plugins: [
    new webpack.ProvidePlugin({
      Buffer: ["buffer", "Buffer"],
      process: "process/browser",
    }),
  ]

  /* ... */
}
Run Code Online (Sandbox Code Playgroud)

但是 a) webstorm 发誓,b) 该项目不是由 …

reactjs webpack create-react-app react-pdf

4
推荐指数
1
解决办法
1万
查看次数

Webpack 不获取本地 node_modules 更新

我有一个A依赖于 package 的包B。我用来在本地yalc更新B和发布更改,以便A可以获取这些更改。

我可以看到更改已复制到 的文件夹中A,node_modules但是 webpack 似乎没有拾取它们。A在开发服务器中运行时,我仍然看到旧代码。重新启动开发服务器没有帮助。甚至yarn install --check-files没有帮助。唯一有帮助的就是用核武器摧毁整个系统node_modules并重新安装。

项目A是用以下命令创建的create-react-app

package.json有以下内容:

dependencies: {
...
@company_name/project_name: "file:.yalc@company_name/project_name"
... }
Run Code Online (Sandbox Code Playgroud)

我在用yarn 1.22

webpack webpack-dev-server create-react-app yarn-link yalc

4
推荐指数
1
解决办法
1059
查看次数

如何禁用浏览器中显示的 eslint 错误

当我使用 npm start 运行 create React app 应用程序时,eslint 错误显示在我网站顶部的浏览器中。我希望在终端中看到这些警告和错误,但在实际网站中看不到,我该如何删除它?

在此输入图像描述

包.json

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.11.0",
    "react-dom": "^16.11.0",
    "react-router-dom": "^5.1.2",
    "react-scripts": "^5.0.0",
    "react-transition-group": "^4.3.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "lint": "eslint ."
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }, …
Run Code Online (Sandbox Code Playgroud)

reactjs eslint create-react-app eslint-config-airbnb

4
推荐指数
2
解决办法
1万
查看次数

GENERATE_SOURCEMAP=false 的副作用是什么?

在项目中使用 sv2pdf 时,我遇到了Failed to parse source map错误。我找到了这个解决方案,现在已经解决了。解决方案是仅添加GENERATE_SOURCEMAP=false到文件中.env。

但是,我不确定该解决方案可能产生的副作用。根据官方 Create React App文档development,它在in 中但在 中使用时被忽略production。我使用这个会冒什么风险吗?

javascript node.js reactjs webpack create-react-app

4
推荐指数
1
解决办法
4697
查看次数

如何从生产版本中删除 data-testid

我想从生产版本中删除 data-testid,因此在产品版本中找不到这些属性特别是在这种情况下,我需要一些与 .tsx 文件一起使用的东西我知道如何使用组件中的函数删除它,但我认为应该有一种更聪明的方法来做到这一点。反应 cra 反应应用程序重新连线

reactjs create-react-app

4
推荐指数
1
解决办法
4947
查看次数

如何调试挂起的反应脚本?

我正在使用AWS ECS上的docker部署create-react-app。我正在使用dockerhub映像进行测试,该映像几乎是create-react-app的原始版本。启动任务时,它能够拉出容器映像,启动docker容器,但是它挂在运行react-scripts start上。我在容器日志中看到的全部是:

01:51:38 npm info it worked if it ends with ok
01:51:38 npm info using npm@2.15.11
01:51:38 npm info using node@v4.7.3
01:51:42 npm info prestart test-react@0.1.0
01:51:42 npm info start test-react@0.1.0
01:51:42 > test-react@0.1.0 start /usr/src/app
01:51:42 > react-scripts start
01:52:06 Starting the development server...
Run Code Online (Sandbox Code Playgroud)

它只是挂在那里,永远不会完成。但是,当我手动运行docker容器时,一切正常:

Starting the development server...
Compiled successfully!

The app is running at:

  http://localhost:3000/
Run Code Online (Sandbox Code Playgroud)

我的Dockerfile是:

FROM node:4-onbuild

# Prepare app directory
RUN mkdir -p /usr/src/app
ADD . /usr/src/app

# Install dependencies
WORKDIR /usr/src/app
RUN …
Run Code Online (Sandbox Code Playgroud)

amazon-ecs reactjs create-react-app

3
推荐指数
1
解决办法
2545
查看次数

我如何使用Jest在测试文件上获取window.location.pathname?

我有React应用是通过用玩笑和酶进行create-react-app制作的

那么如何获取window.location.pathname测试文件内部的值?

这是我的规格

import React from 'react';
import MovieDetailsBox from '../../src/components/movie_single/MovieDetailsBox';
import { expect } from 'chai';
import { shallow } from 'enzyme';
import { movie_details } from '../../src/data/movies_details'
import { empty_user } from '../../src/helper/sessionHelper';

jest.mock('react-router');

describe('Test <MovieDetailsBox /> Component', () => {

    let movie_details_props = {
        movie: {...movie_details}
    }

    let user_props = {

    }

    const context = { router: { isActive: (a, b) => true } }

    const wrapper = shallow(
        <MovieDetailsBox movie={movie_details_props}
                         user={user_props}
                         currentPath={'/movie/68'}/>, { context …
Run Code Online (Sandbox Code Playgroud)

reactjs jestjs enzyme create-react-app

3
推荐指数
3
解决办法
1万
查看次数