标签: create-react-app

如何使用 npm 安装所有要求?

我想克隆https://github.com/tstringer/create-react-app-with-redux并开始一个新项目。我跑了npm start然后跑npm install了每个不存在的模块,但有很多。有没有办法安装所有要求?类似于pip install -r requirements.txtPython 中的东西。

谢谢,乌里。

node.js reactjs redux create-react-app

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

Jest 测试仅在覆盖范围内失败

我有一个问题,如果我在没有--coverage选项的情况下运行我的测试,一切都会通过,但是一旦我jest使用该--coverage选项运行,我的一些测试就会失败。

这是日志:

Button › Primary button › should render a primary button

  undefined:3:457: property missing ':'

  at Object.it (src/components/Buttons/Button/Button.test.js:13:24)
  at Promise.resolve.then.el (node_modules/p-map/index.js:46:16)
Run Code Online (Sandbox Code Playgroud)

和测试:

it('should render a primary button', () => {
  const props = { primary: true };

  const rendered = renderer.create(<Button { ...props }>Some Button</Button>).toJSON();
  expect(rendered).toMatchSnapshot();
});
Run Code Online (Sandbox Code Playgroud)

失败的线路是 expect(rendered).toMatchSnapshot();

有人有什么想法吗?

istanbul reactjs jestjs create-react-app

7
推荐指数
1
解决办法
1408
查看次数

Material-ui覆盖反应情绪规则

在我的项目中,我使用Material-ui组件以及react-emotion.

让我举一个有问题的例子.我有这个元素:

<CardHeader title={stat} classes={{ root: statNumber }}/>
Run Code Online (Sandbox Code Playgroud)

哪里

const statNumber = css`padding: 0;`
Run Code Online (Sandbox Code Playgroud)

这样我就可以覆盖CardHeader的默认填充(16px)0,这是我的意图.

在开发模式下,一切都按预期工作,但在生产中,填充:0规则被默认填充16px覆盖.

发生这种情况的原因是在开发模式下,样式会动态添加到标题中.首先是Material-UI样式,然后是情感样式.像这样: 发展模式

但在制作中,风格却是相反的

生产模式

这就是在生产模式中覆盖样式的原因.

材料ui对此https://material-ui-next.com/customization/css-in-js/#css-injection-order提供了解释

但是随着解决方案的提出,我无法改变情感和材料的顺序 - ui风格是有序的.我只能改变材料ui并将其向下移动

任何人都知道如何解决这个问题?

emotion reactjs material-ui create-react-app

7
推荐指数
2
解决办法
1464
查看次数

创建 React App 找不到测试

我最近使用 create-react-app 启动了一个新项目。我将文件夹App.test.js从外部移动/src到根级/tests文件夹中,因此我的文件夹结构现在如下所示:

> node_modules
> public
> src
   ...
   App.js
> tests
   App.test.js
...
Run Code Online (Sandbox Code Playgroud)

这是整个 App.test.js 文件:

import React from 'react';
import ReactDOM from 'react-dom';
import App from "../src/App";

it('renders without crashing', () => {
  const div = document.createElement('div');
  ReactDOM.render(<App />, div);
  ReactDOM.unmountComponentAtNode(div);
});
Run Code Online (Sandbox Code Playgroud)

因此,当我尝试时npm run test,不会执行任何测试。它说找不到测试。如何让 create-react-app 将新/tests文件夹识别为所有测试的新位置并运行它们?

regex testing reactjs jestjs create-react-app

7
推荐指数
1
解决办法
4728
查看次数

如何将 create-react-app 部署到 Google Cloud

我有一个前端 create-react-app 和一个使用 Expressjs 的后端 API。

我成功地将后端 API 部署到了 Google App Engine。

但是现在我需要将 create-react-app 部署到 Google Cloud 并且变得非常混乱,我尝试了一段时间的 google 并且没有正确/推荐的方法。

至少我看到其他人建议以两种方式进行:

  1. 使用谷歌云存储:

    • 运行“npm run build”来创建“build”文件夹

    • 将整个文件夹上传到存储桶中

=> 我发现使用这种方式有一个缺点:当我尝试重新加载页面 'url/aboutUs' 时,它没有找到。所以我必须回到“url”然后点击关于我们链接

=> 我猜我使用的 React Router 不能与 Google Cloud Storage 配合使用

  1. 使用 Google 应用引擎

=> 人们刚刚谈到使用它,但我找不到任何指南/教程。

那么将 create-react-app 部署到 Google Cloud 的推荐方法是什么?

你能提供一个教程吗?

谢谢。

google-app-engine google-cloud-storage reactjs google-cloud-platform create-react-app

7
推荐指数
1
解决办法
5752
查看次数

ESlint 抛出错误而不是警告

是否可以使用 Eslint 抛出错误而不是警告?我正在与 a 合作create-react-app并希望在我的团队中有一个非常严格的 lint 政策,并认为这可能是一个好的开始。

那可能吗?

javascript eslint create-react-app

7
推荐指数
1
解决办法
4672
查看次数

在某个浏览器中运行 create-react-app

是否可以create-react-app在我选择的某个浏览器中启动应用程序?目前,它总是在 Chrome 中运行,而我希望它在 Chrome Canary 中运行。有人知道吗?

node.js create-react-app

7
推荐指数
3
解决办法
7498
查看次数

来自 create-react-app 的玩笑不在 Windows 上运行

我在从create-react-app在 Windows 8.1 上创建的干净安装的应用程序运行 Jest 时遇到问题。安装后,运行命令npm run test,我收到错误:

No tests found related to files changed since last commit.

Running jest --watchAll,因此绕过 react-scripts,在同一目录中,虽然,显示:

Test suite failed to run

Jest encountered an unexpected token

This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

Here's what you can do: …
Run Code Online (Sandbox Code Playgroud)

reactjs jestjs babeljs babel-jest create-react-app

7
推荐指数
2
解决办法
4205
查看次数

console.log(Wrapper.debug()) 没有显示反应组件

我正在使用带有玩笑的酶并尝试打印出 wrapper.debug 但我没有得到像 jest 文档中所示的输出。这里有什么问题?我的测试文件:

import React  from 'react';
import Enzyme, {shallow} from 'enzyme';
import EnzymeAdapter from 'enzyme-adapter-react-16';
import App  from './../../components/App/App';



Enzyme.configure({ adapter : new EnzymeAdapter() });

it('should render without crashing', () => {
  const wrapper = shallow(<App />)


 console.log(wrapper.debug());

});
Run Code Online (Sandbox Code Playgroud)

我的控制台输出是这样的:

 PASS  src/test/integration/App.test.js
  ? Console

    console.log src/test/integration/App.test.js:14
      <ContextConsumer>
        [function bound renderWrappedComponent]
      </ContextConsumer>


Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.8s
Ran all test suites related to changed files.
Run Code Online (Sandbox Code Playgroud)

testing jestjs enzyme create-react-app

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

Reactstrap Bootstrap Navbar 在 React 应用程序中不起作用

我用“create react-app”创建了一个反应应用程序。

我现在正在尝试从 Reactstrap 添加导航栏。我从 Reactstrap(我将它添加为一个 React 组件)网站进行复制粘贴:

import React from 'react';
import {
  Collapse,
  Navbar,
  NavbarToggler,
  NavbarBrand,
  Nav,
  NavItem,
  NavLink,
  UncontrolledDropdown,
  DropdownToggle,
  DropdownMenu,
  DropdownItem } from 'reactstrap';

export default class Example extends React.Component {
  constructor(props) {
    super(props);

    this.toggle = this.toggle.bind(this);
    this.state = {
      isOpen: false
    };
  }
  toggle() {
    this.setState({
      isOpen: !this.state.isOpen
    });
  }
  render() {
    return (
      <div>
        <Navbar color="light" light expand="md">
          <NavbarBrand href="/">reactstrap</NavbarBrand>
          <NavbarToggler onClick={this.toggle} />
          <Collapse isOpen={this.state.isOpen} navbar>
            <Nav className="ml-auto" navbar>
              <NavItem>
                <NavLink href="/components/">Components</NavLink> …
Run Code Online (Sandbox Code Playgroud)

navbar reactjs bootstrap-4 create-react-app reactstrap

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